<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Matrix - matrix: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><span class="include">Enumerable</span>
    <li><a class="include" href="ExceptionForMatrix.html">ExceptionForMatrix</a>
  </ul>
</div>

        
<div id="extends-section" class="nav-section">
  <h3>Extended With Modules</h3>

  <ul class="link-list">
    <li><span class="extend">ConversionHelper</span>
  </ul>
</div>

        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-I">::I</a>
    <li ><a href="#method-c-5B-5D">::[]</a>
    <li ><a href="#method-c-build">::build</a>
    <li ><a href="#method-c-column_vector">::column_vector</a>
    <li ><a href="#method-c-columns">::columns</a>
    <li ><a href="#method-c-combine">::combine</a>
    <li ><a href="#method-c-diagonal">::diagonal</a>
    <li ><a href="#method-c-empty">::empty</a>
    <li ><a href="#method-c-hstack">::hstack</a>
    <li ><a href="#method-c-identity">::identity</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-c-row_vector">::row_vector</a>
    <li ><a href="#method-c-rows">::rows</a>
    <li ><a href="#method-c-scalar">::scalar</a>
    <li ><a href="#method-c-unit">::unit</a>
    <li ><a href="#method-c-vstack">::vstack</a>
    <li ><a href="#method-c-zero">::zero</a>
    <li ><a href="#method-i-2A">#*</a>
    <li ><a href="#method-i-2A-2A">#**</a>
    <li ><a href="#method-i-2B">#+</a>
    <li ><a href="#method-i-2B-40">#+@</a>
    <li ><a href="#method-i-2D">#-</a>
    <li ><a href="#method-i-2D-40">#-@</a>
    <li ><a href="#method-i-2F">#/</a>
    <li ><a href="#method-i-3D-3D">#==</a>
    <li ><a href="#method-i-5B-5D">#[]</a>
    <li ><a href="#method-i-5B-5D-3D">#[]=</a>
    <li ><a href="#method-i-abs">#abs</a>
    <li ><a href="#method-i-adjoint">#adjoint</a>
    <li ><a href="#method-i-adjugate">#adjugate</a>
    <li ><a href="#method-i-antisymmetric-3F">#antisymmetric?</a>
    <li ><a href="#method-i-check_int">#check_int</a>
    <li ><a href="#method-i-check_range">#check_range</a>
    <li ><a href="#method-i-coerce">#coerce</a>
    <li ><a href="#method-i-cofactor">#cofactor</a>
    <li ><a href="#method-i-cofactor_expansion">#cofactor_expansion</a>
    <li ><a href="#method-i-collect">#collect</a>
    <li ><a href="#method-i-collect-21">#collect!</a>
    <li ><a href="#method-i-column">#column</a>
    <li ><a href="#method-i-column_vectors">#column_vectors</a>
    <li ><a href="#method-i-combine">#combine</a>
    <li ><a href="#method-i-component">#component</a>
    <li ><a href="#method-i-conj">#conj</a>
    <li ><a href="#method-i-conjugate">#conjugate</a>
    <li ><a href="#method-i-det">#det</a>
    <li ><a href="#method-i-det_e">#det_e</a>
    <li ><a href="#method-i-determinant">#determinant</a>
    <li ><a href="#method-i-determinant_bareiss">#determinant_bareiss</a>
    <li ><a href="#method-i-determinant_e">#determinant_e</a>
    <li ><a href="#method-i-diagonal-3F">#diagonal?</a>
    <li ><a href="#method-i-each">#each</a>
    <li ><a href="#method-i-each_with_index">#each_with_index</a>
    <li ><a href="#method-i-eigen">#eigen</a>
    <li ><a href="#method-i-eigensystem">#eigensystem</a>
    <li ><a href="#method-i-element">#element</a>
    <li ><a href="#method-i-elements_to_f">#elements_to_f</a>
    <li ><a href="#method-i-elements_to_i">#elements_to_i</a>
    <li ><a href="#method-i-elements_to_r">#elements_to_r</a>
    <li ><a href="#method-i-empty-3F">#empty?</a>
    <li ><a href="#method-i-entrywise_product">#entrywise_product</a>
    <li ><a href="#method-i-eql-3F">#eql?</a>
    <li ><a href="#method-i-find_index">#find_index</a>
    <li ><a href="#method-i-first_minor">#first_minor</a>
    <li class="calls-super" ><a href="#method-i-freeze">#freeze</a>
    <li ><a href="#method-i-hadamard_product">#hadamard_product</a>
    <li ><a href="#method-i-hash">#hash</a>
    <li ><a href="#method-i-hermitian-3F">#hermitian?</a>
    <li ><a href="#method-i-hstack">#hstack</a>
    <li ><a href="#method-i-imag">#imag</a>
    <li ><a href="#method-i-imaginary">#imaginary</a>
    <li ><a href="#method-i-index">#index</a>
    <li class="calls-super" ><a href="#method-i-initialize_copy">#initialize_copy</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-inv">#inv</a>
    <li ><a href="#method-i-inverse">#inverse</a>
    <li ><a href="#method-i-laplace_expansion">#laplace_expansion</a>
    <li ><a href="#method-i-lower_triangular-3F">#lower_triangular?</a>
    <li ><a href="#method-i-lup">#lup</a>
    <li ><a href="#method-i-lup_decomposition">#lup_decomposition</a>
    <li ><a href="#method-i-map">#map</a>
    <li ><a href="#method-i-map-21">#map!</a>
    <li ><a href="#method-i-minor">#minor</a>
    <li ><a href="#method-i-normal-3F">#normal?</a>
    <li ><a href="#method-i-orthogonal-3F">#orthogonal?</a>
    <li ><a href="#method-i-permutation-3F">#permutation?</a>
    <li ><a href="#method-i-power_int">#power_int</a>
    <li ><a href="#method-i-rank">#rank</a>
    <li ><a href="#method-i-rank_e">#rank_e</a>
    <li ><a href="#method-i-real">#real</a>
    <li ><a href="#method-i-real-3F">#real?</a>
    <li ><a href="#method-i-rect">#rect</a>
    <li ><a href="#method-i-rectangular">#rectangular</a>
    <li ><a href="#method-i-regular-3F">#regular?</a>
    <li ><a href="#method-i-rotate_entries">#rotate_entries</a>
    <li ><a href="#method-i-round">#round</a>
    <li ><a href="#method-i-row">#row</a>
    <li ><a href="#method-i-row_count">#row_count</a>
    <li ><a href="#method-i-row_size">#row_size</a>
    <li ><a href="#method-i-row_vectors">#row_vectors</a>
    <li ><a href="#method-i-set_col_range">#set_col_range</a>
    <li ><a href="#method-i-set_column_vector">#set_column_vector</a>
    <li ><a href="#method-i-set_component">#set_component</a>
    <li ><a href="#method-i-set_element">#set_element</a>
    <li ><a href="#method-i-set_row_and_col_range">#set_row_and_col_range</a>
    <li ><a href="#method-i-set_row_range">#set_row_range</a>
    <li ><a href="#method-i-set_value">#set_value</a>
    <li ><a href="#method-i-singular-3F">#singular?</a>
    <li ><a href="#method-i-skew_symmetric-3F">#skew_symmetric?</a>
    <li ><a href="#method-i-square-3F">#square?</a>
    <li ><a href="#method-i-symmetric-3F">#symmetric?</a>
    <li ><a href="#method-i-t">#t</a>
    <li ><a href="#method-i-to_a">#to_a</a>
    <li ><a href="#method-i-to_matrix">#to_matrix</a>
    <li ><a href="#method-i-to_s">#to_s</a>
    <li ><a href="#method-i-tr">#tr</a>
    <li ><a href="#method-i-trace">#trace</a>
    <li ><a href="#method-i-transpose">#transpose</a>
    <li ><a href="#method-i-unitary-3F">#unitary?</a>
    <li ><a href="#method-i-upper_triangular-3F">#upper_triangular?</a>
    <li ><a href="#method-i-vstack">#vstack</a>
    <li ><a href="#method-i-zero-3F">#zero?</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Matrix">
    <h1 id="class-Matrix" class="class">
      class Matrix
    </h1>

    <section class="description">
    
<p>The <code>Matrix</code> class represents a mathematical matrix. It provides methods for creating matrices, operating on them arithmetically and algebraically, and determining their mathematical properties such as trace, rank, inverse, determinant, or eigensystem.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="SELECTORS">SELECTORS
          <dd>
          <dt id="VERSION">VERSION
          <dd>
        </dl>
        </section>

        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-i-column_count" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">column_count</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the number of columns.</p>
              </div>
            </div>
          <div id="attribute-i-column_size" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">column_size</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the number of columns.</p>
              </div>
            </div>
          <div id="attribute-i-rows" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">rows</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>instance creations</p>
              </div>
            </div>
            </section>


                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-I" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">I</span><span
                                class="method-args">(n)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-c-identity">identity</a>
                            </div>
                          </div>

                  <div id="method-c-5B-5D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">[]</span><span
                                class="method-args">(*rows)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a matrix where each argument is a row.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[ [<span class="ruby-value">25</span>, <span class="ruby-value">93</span>], [<span class="ruby-value">-1</span>, <span class="ruby-value">66</span>] ]
<span class="ruby-comment">#   =&gt;  25 93</span>
<span class="ruby-comment">#       -1 66</span>
</pre>

                              <div class="method-source-code" id="5B-5D-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 78</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">[]</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">rows</span>)
  <span class="ruby-identifier">rows</span>(<span class="ruby-identifier">rows</span>, <span class="ruby-keyword">false</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-build" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">build</span><span
                                class="method-args">(row_count, column_count = row_count) { |i, j| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a matrix of size <code>row_count</code> x <code>column_count</code>. It fills the values by calling the given block, passing the current row and column. Returns an enumerator if no block is given.</p>

<pre class="ruby"><span class="ruby-identifier">m</span> = <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">build</span>(<span class="ruby-value">2</span>, <span class="ruby-value">4</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">col</span><span class="ruby-operator">|</span> <span class="ruby-identifier">col</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">row</span> }
<span class="ruby-comment">#  =&gt; Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]]</span>
<span class="ruby-identifier">m</span> = <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">build</span>(<span class="ruby-value">3</span>) { <span class="ruby-identifier">rand</span> }
<span class="ruby-comment">#  =&gt; a 3x3 matrix with random elements</span>
</pre>

                              <div class="method-source-code" id="build-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 123</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">build</span>(<span class="ruby-identifier">row_count</span>, <span class="ruby-identifier">column_count</span> = <span class="ruby-identifier">row_count</span>)
  <span class="ruby-identifier">row_count</span> = <span class="ruby-constant">CoercionHelper</span>.<span class="ruby-identifier">coerce_to_int</span>(<span class="ruby-identifier">row_count</span>)
  <span class="ruby-identifier">column_count</span> = <span class="ruby-constant">CoercionHelper</span>.<span class="ruby-identifier">coerce_to_int</span>(<span class="ruby-identifier">column_count</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">row_count</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">column_count</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span> <span class="ruby-value">:build</span>, <span class="ruby-identifier">row_count</span>, <span class="ruby-identifier">column_count</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
  <span class="ruby-identifier">rows</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">row_count</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">column_count</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">yield</span> <span class="ruby-identifier">i</span>, <span class="ruby-identifier">j</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">new</span> <span class="ruby-identifier">rows</span>, <span class="ruby-identifier">column_count</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-column_vector" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">column_vector</span><span
                                class="method-args">(column)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a single-column matrix where the values of that column are as given in <code>column</code>.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">column_vector</span>([<span class="ruby-value">4</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>])
<span class="ruby-comment">#  =&gt; 4</span>
<span class="ruby-comment">#     5</span>
<span class="ruby-comment">#     6</span>
</pre>

                              <div class="method-source-code" id="column_vector-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 209</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">column_vector</span>(<span class="ruby-identifier">column</span>)
  <span class="ruby-identifier">column</span> = <span class="ruby-identifier">convert_to_array</span>(<span class="ruby-identifier">column</span>)
  <span class="ruby-identifier">new</span> [<span class="ruby-identifier">column</span>].<span class="ruby-identifier">transpose</span>, <span class="ruby-value">1</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-columns" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">columns</span><span
                                class="method-args">(columns)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a matrix using <code>columns</code> as an array of column vectors.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">columns</span>([[<span class="ruby-value">25</span>, <span class="ruby-value">93</span>], [<span class="ruby-value">-1</span>, <span class="ruby-value">66</span>]])
<span class="ruby-comment">#   =&gt;  25 -1</span>
<span class="ruby-comment">#       93 66</span>
</pre>

                              <div class="method-source-code" id="columns-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 108</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">columns</span>(<span class="ruby-identifier">columns</span>)
  <span class="ruby-identifier">rows</span>(<span class="ruby-identifier">columns</span>, <span class="ruby-keyword">false</span>).<span class="ruby-identifier">transpose</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-combine" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          combine(*matrices) { |*elements| ... }
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Create a matrix by combining matrices entrywise, using the given block</p>

<pre class="ruby"><span class="ruby-identifier">x</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">6</span>, <span class="ruby-value">6</span>], [<span class="ruby-value">4</span>, <span class="ruby-value">4</span>]]
<span class="ruby-identifier">y</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>], [<span class="ruby-value">3</span>, <span class="ruby-value">4</span>]]
<span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">combine</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">b</span>} <span class="ruby-comment"># =&gt; Matrix[[5, 4], [1, 0]]</span>
</pre>

                              <div class="method-source-code" id="combine-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 288</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">combine</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">matrices</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span>(<span class="ruby-identifier">__method__</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">matrices</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>

  <span class="ruby-keyword">return</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">empty</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">matrices</span>.<span class="ruby-identifier">empty?</span>
  <span class="ruby-identifier">matrices</span>.<span class="ruby-identifier">map!</span>(<span class="ruby-operator">&amp;</span><span class="ruby-constant">CoercionHelper</span>.<span class="ruby-identifier">method</span>(<span class="ruby-value">:coerce_to_matrix</span>))
  <span class="ruby-identifier">x</span> = <span class="ruby-identifier">matrices</span>.<span class="ruby-identifier">first</span>
  <span class="ruby-identifier">matrices</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">row_count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">row_count</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">column_count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">column_count</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">rows</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">x</span>.<span class="ruby-identifier">row_count</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">x</span>.<span class="ruby-identifier">column_count</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">yield</span> <span class="ruby-identifier">matrices</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-identifier">m</span>[<span class="ruby-identifier">i</span>,<span class="ruby-identifier">j</span>]}
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">new</span> <span class="ruby-identifier">rows</span>, <span class="ruby-identifier">x</span>.<span class="ruby-identifier">column_count</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-diagonal" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">diagonal</span><span
                                class="method-args">(*values)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a matrix where the diagonal elements are composed of <code>values</code>.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">diagonal</span>(<span class="ruby-value">9</span>, <span class="ruby-value">5</span>, <span class="ruby-value">-3</span>)
<span class="ruby-comment">#  =&gt;  9  0  0</span>
<span class="ruby-comment">#      0  5  0</span>
<span class="ruby-comment">#      0  0 -3</span>
</pre>

                              <div class="method-source-code" id="diagonal-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 143</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">diagonal</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">values</span>)
  <span class="ruby-identifier">size</span> = <span class="ruby-identifier">values</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-keyword">return</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">empty</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
  <span class="ruby-identifier">rows</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">size</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">row</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">size</span>, <span class="ruby-value">0</span>)
    <span class="ruby-identifier">row</span>[<span class="ruby-identifier">j</span>] = <span class="ruby-identifier">values</span>[<span class="ruby-identifier">j</span>]
    <span class="ruby-identifier">row</span>
  }
  <span class="ruby-identifier">new</span> <span class="ruby-identifier">rows</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-empty" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">empty</span><span
                                class="method-args">(row_count = 0, column_count = 0)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a empty matrix of <code>row_count</code> x <code>column_count</code>. At least one of <code>row_count</code> or <code>column_count</code> must be 0.</p>

<pre class="ruby"><span class="ruby-identifier">m</span> = <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">empty</span>(<span class="ruby-value">2</span>, <span class="ruby-value">0</span>)
<span class="ruby-identifier">m</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Matrix</span>[ [], [] ]
<span class="ruby-comment">#  =&gt; true</span>
<span class="ruby-identifier">n</span> = <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">empty</span>(<span class="ruby-value">0</span>, <span class="ruby-value">3</span>)
<span class="ruby-identifier">n</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">columns</span>([ [], [], [] ])
<span class="ruby-comment">#  =&gt; true</span>
<span class="ruby-identifier">m</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">n</span>
<span class="ruby-comment">#  =&gt; Matrix[[0, 0, 0], [0, 0, 0]]</span>
</pre>

                              <div class="method-source-code" id="empty-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 227</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">empty</span>(<span class="ruby-identifier">row_count</span> = <span class="ruby-value">0</span>, <span class="ruby-identifier">column_count</span> = <span class="ruby-value">0</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;One size must be 0&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">column_count</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">row_count</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Negative size&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">column_count</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">row_count</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>

  <span class="ruby-identifier">new</span>([[]]<span class="ruby-operator">*</span><span class="ruby-identifier">row_count</span>, <span class="ruby-identifier">column_count</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-hstack" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">hstack</span><span
                                class="method-args">(x, *matrices)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Create a matrix by stacking matrices horizontally</p>

<pre class="ruby"><span class="ruby-identifier">x</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>], [<span class="ruby-value">3</span>, <span class="ruby-value">4</span>]]
<span class="ruby-identifier">y</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">5</span>, <span class="ruby-value">6</span>], [<span class="ruby-value">7</span>, <span class="ruby-value">8</span>]]
<span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">hstack</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span>) <span class="ruby-comment"># =&gt; Matrix[[1, 2, 5, 6], [3, 4, 7, 8]]</span>
</pre>

                              <div class="method-source-code" id="hstack-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 262</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">hstack</span>(<span class="ruby-identifier">x</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">matrices</span>)
  <span class="ruby-identifier">x</span> = <span class="ruby-constant">CoercionHelper</span>.<span class="ruby-identifier">coerce_to_matrix</span>(<span class="ruby-identifier">x</span>)
  <span class="ruby-identifier">result</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:rows</span>).<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:dup</span>)
  <span class="ruby-identifier">total_column_count</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">column_count</span>
  <span class="ruby-identifier">matrices</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">m</span> = <span class="ruby-constant">CoercionHelper</span>.<span class="ruby-identifier">coerce_to_matrix</span>(<span class="ruby-identifier">m</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">row_count</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">row_count</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span>, <span class="ruby-node">&quot;The given matrices must have #{x.row_count} rows, but one has #{m.row_count}&quot;</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">result</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">row</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:rows</span>)[<span class="ruby-identifier">i</span>]
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">total_column_count</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">column_count</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">new</span> <span class="ruby-identifier">result</span>, <span class="ruby-identifier">total_column_count</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-identity" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">identity</span><span
                                class="method-args">(n)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates an <code>n</code> by <code>n</code> identity matrix.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">identity</span>(<span class="ruby-value">2</span>)
<span class="ruby-comment">#  =&gt; 1 0</span>
<span class="ruby-comment">#     0 1</span>
</pre>

                              <div class="method-source-code" id="identity-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 171</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">identity</span>(<span class="ruby-identifier">n</span>)
  <span class="ruby-identifier">scalar</span>(<span class="ruby-identifier">n</span>, <span class="ruby-value">1</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-c-unit">unit</a>, <a href="Matrix.html#method-c-I">I</a>
                            </div>

                          </div>

                  <div id="method-c-new" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new</span><span
                                class="method-args">(rows, column_count = rows[0].size)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="Matrix.html#method-c-new"><code>Matrix.new</code></a> is private; use <a href="Matrix.html#method-c-rows"><code>::rows</code></a>, <a href="Matrix.html#method-c-columns"><code>::columns</code></a>, <a href="Matrix.html#method-c-5B-5D"><code>::[]</code></a>, etc… to create.</p>

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 322</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">rows</span>, <span class="ruby-identifier">column_count</span> = <span class="ruby-identifier">rows</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">size</span>)
  <span class="ruby-comment"># No checking is done at this point. rows must be an Array of Arrays.</span>
  <span class="ruby-comment"># column_count must be the size of the first row, if there is one,</span>
  <span class="ruby-comment"># otherwise it *must* be specified and can be any integer &gt;= 0</span>
  <span class="ruby-ivar">@rows</span> = <span class="ruby-identifier">rows</span>
  <span class="ruby-ivar">@column_count</span> = <span class="ruby-identifier">column_count</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-row_vector" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">row_vector</span><span
                                class="method-args">(row)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a single-row matrix where the values of that row are as given in <code>row</code>.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">row_vector</span>([<span class="ruby-value">4</span>,<span class="ruby-value">5</span>,<span class="ruby-value">6</span>])
<span class="ruby-comment">#  =&gt; 4 5 6</span>
</pre>

                              <div class="method-source-code" id="row_vector-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 196</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">row_vector</span>(<span class="ruby-identifier">row</span>)
  <span class="ruby-identifier">row</span> = <span class="ruby-identifier">convert_to_array</span>(<span class="ruby-identifier">row</span>)
  <span class="ruby-identifier">new</span> [<span class="ruby-identifier">row</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-rows" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">rows</span><span
                                class="method-args">(rows, copy = true)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a matrix where <code>rows</code> is an array of arrays, each of which is a row of the matrix.  If the optional argument <code>copy</code> is false, use the given arrays as the internal structure of the matrix without copying.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">rows</span>([[<span class="ruby-value">25</span>, <span class="ruby-value">93</span>], [<span class="ruby-value">-1</span>, <span class="ruby-value">66</span>]])
<span class="ruby-comment">#   =&gt;  25 93</span>
<span class="ruby-comment">#       -1 66</span>
</pre>

                              <div class="method-source-code" id="rows-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 90</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">rows</span>(<span class="ruby-identifier">rows</span>, <span class="ruby-identifier">copy</span> = <span class="ruby-keyword">true</span>)
  <span class="ruby-identifier">rows</span> = <span class="ruby-identifier">convert_to_array</span>(<span class="ruby-identifier">rows</span>, <span class="ruby-identifier">copy</span>)
  <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">map!</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">convert_to_array</span>(<span class="ruby-identifier">row</span>, <span class="ruby-identifier">copy</span>)
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">size</span> = (<span class="ruby-identifier">rows</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">||</span> []).<span class="ruby-identifier">size</span>
  <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span>, <span class="ruby-node">&quot;row size differs (#{row.size} should be #{size})&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">size</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">new</span> <span class="ruby-identifier">rows</span>, <span class="ruby-identifier">size</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-scalar" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">scalar</span><span
                                class="method-args">(n, value)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates an <code>n</code> by <code>n</code> diagonal matrix where each diagonal element is <code>value</code>.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">scalar</span>(<span class="ruby-value">2</span>, <span class="ruby-value">5</span>)
<span class="ruby-comment">#  =&gt; 5 0</span>
<span class="ruby-comment">#     0 5</span>
</pre>

                              <div class="method-source-code" id="scalar-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 161</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">scalar</span>(<span class="ruby-identifier">n</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">diagonal</span>(<span class="ruby-operator">*</span><span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">n</span>, <span class="ruby-identifier">value</span>))
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-unit" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">unit</span><span
                                class="method-args">(n)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-c-identity">identity</a>
                            </div>
                          </div>

                  <div id="method-c-vstack" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">vstack</span><span
                                class="method-args">(x, *matrices)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Create a matrix by stacking matrices vertically</p>

<pre class="ruby"><span class="ruby-identifier">x</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>], [<span class="ruby-value">3</span>, <span class="ruby-value">4</span>]]
<span class="ruby-identifier">y</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">5</span>, <span class="ruby-value">6</span>], [<span class="ruby-value">7</span>, <span class="ruby-value">8</span>]]
<span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">vstack</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span>) <span class="ruby-comment"># =&gt; Matrix[[1, 2], [3, 4], [5, 6], [7, 8]]</span>
</pre>

                              <div class="method-source-code" id="vstack-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 241</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">vstack</span>(<span class="ruby-identifier">x</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">matrices</span>)
  <span class="ruby-identifier">x</span> = <span class="ruby-constant">CoercionHelper</span>.<span class="ruby-identifier">coerce_to_matrix</span>(<span class="ruby-identifier">x</span>)
  <span class="ruby-identifier">result</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:rows</span>).<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:dup</span>)
  <span class="ruby-identifier">matrices</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">m</span> = <span class="ruby-constant">CoercionHelper</span>.<span class="ruby-identifier">coerce_to_matrix</span>(<span class="ruby-identifier">m</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">column_count</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">column_count</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span>, <span class="ruby-node">&quot;The given matrices must have #{x.column_count} columns, but one has #{m.column_count}&quot;</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">result</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:rows</span>))
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">new</span> <span class="ruby-identifier">result</span>, <span class="ruby-identifier">x</span>.<span class="ruby-identifier">column_count</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-zero" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">zero</span><span
                                class="method-args">(row_count, column_count = row_count)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a zero matrix.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">zero</span>(<span class="ruby-value">2</span>)
<span class="ruby-comment">#  =&gt; 0 0</span>
<span class="ruby-comment">#     0 0</span>
</pre>

                              <div class="method-source-code" id="zero-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 185</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier ruby-title">zero</span>(<span class="ruby-identifier">row_count</span>, <span class="ruby-identifier">column_count</span> = <span class="ruby-identifier">row_count</span>)
  <span class="ruby-identifier">rows</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">row_count</span>){<span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">column_count</span>, <span class="ruby-value">0</span>)}
  <span class="ruby-identifier">new</span> <span class="ruby-identifier">rows</span>, <span class="ruby-identifier">column_count</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-2A" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">*</span><span
                                class="method-args">(m)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="Matrix.html"><code>Matrix</code></a> multiplication.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">2</span>,<span class="ruby-value">4</span>], [<span class="ruby-value">6</span>,<span class="ruby-value">8</span>]] <span class="ruby-operator">*</span> <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">identity</span>(<span class="ruby-value">2</span>)
<span class="ruby-comment">#  =&gt; 2 4</span>
<span class="ruby-comment">#     6 8</span>
</pre>

                              <div class="method-source-code" id="2A-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1058</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">*</span>(<span class="ruby-identifier">m</span>) <span class="ruby-comment"># m is matrix or vector or number</span>
  <span class="ruby-keyword">case</span>(<span class="ruby-identifier">m</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Numeric</span>
    <span class="ruby-identifier">new_rows</span> = <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">row</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">m</span> }
    }
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">new_matrix</span> <span class="ruby-identifier">new_rows</span>, <span class="ruby-identifier">column_count</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Vector</span>
    <span class="ruby-identifier">m</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">column_vector</span>(<span class="ruby-identifier">m</span>)
    <span class="ruby-identifier">r</span> = <span class="ruby-keyword">self</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">m</span>
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">column</span>(<span class="ruby-value">0</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Matrix</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">column_count</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">row_count</span>
    <span class="ruby-identifier">m_rows</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">rows</span>
    <span class="ruby-identifier">new_rows</span> = <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row_i</span><span class="ruby-operator">|</span>
      <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">column_count</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">vij</span> = <span class="ruby-value">0</span>
        <span class="ruby-identifier">column_count</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">vij</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">row_i</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m_rows</span>[<span class="ruby-identifier">k</span>][<span class="ruby-identifier">j</span>]
        <span class="ruby-keyword">end</span>
        <span class="ruby-identifier">vij</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">new_matrix</span> <span class="ruby-identifier">new_rows</span>, <span class="ruby-identifier">m</span>.<span class="ruby-identifier">column_count</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">apply_through_coercion</span>(<span class="ruby-identifier">m</span>, <span class="ruby-identifier">__method__</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2A-2A" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">**</span><span
                                class="method-args">(exp)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="Matrix.html"><code>Matrix</code></a> exponentiation. Equivalent to multiplying the matrix by itself N times. Non integer exponents will be handled by diagonalizing the matrix.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">7</span>,<span class="ruby-value">6</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">9</span>]] <span class="ruby-operator">**</span> <span class="ruby-value">2</span>
<span class="ruby-comment">#  =&gt; 67 96</span>
<span class="ruby-comment">#     48 99</span>
</pre>

                              <div class="method-source-code" id="2A-2A-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1237</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">**</span>(<span class="ruby-identifier">exp</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">exp</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Integer</span>
    <span class="ruby-keyword">case</span>
    <span class="ruby-keyword">when</span> <span class="ruby-identifier">exp</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
      <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">identity</span>(<span class="ruby-identifier">column_count</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-identifier">exp</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
      <span class="ruby-identifier">inverse</span>.<span class="ruby-identifier">power_int</span>(<span class="ruby-operator">-</span><span class="ruby-identifier">exp</span>)
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">power_int</span>(<span class="ruby-identifier">exp</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Numeric</span>
    <span class="ruby-identifier">v</span>, <span class="ruby-identifier">d</span>, <span class="ruby-identifier">v_inv</span> = <span class="ruby-identifier">eigensystem</span>
    <span class="ruby-identifier">v</span> <span class="ruby-operator">*</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">diagonal</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">d</span>.<span class="ruby-identifier">each</span>(<span class="ruby-value">:diagonal</span>).<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">**</span> <span class="ruby-identifier">exp</span>}) <span class="ruby-operator">*</span> <span class="ruby-identifier">v_inv</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrOperationNotDefined</span>, [<span class="ruby-string">&quot;**&quot;</span>, <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">exp</span>.<span class="ruby-identifier">class</span>]
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2B" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">+</span><span
                                class="method-args">(m)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="Matrix.html"><code>Matrix</code></a> addition.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">scalar</span>(<span class="ruby-value">2</span>,<span class="ruby-value">5</span>) <span class="ruby-operator">+</span> <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>,<span class="ruby-value">0</span>], [<span class="ruby-value">-4</span>,<span class="ruby-value">7</span>]]
<span class="ruby-comment">#  =&gt;  6  0</span>
<span class="ruby-comment">#     -4 12</span>
</pre>

                              <div class="method-source-code" id="2B-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1093</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">+</span>(<span class="ruby-identifier">m</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">m</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Numeric</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrOperationNotDefined</span>, [<span class="ruby-string">&quot;+&quot;</span>, <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">m</span>.<span class="ruby-identifier">class</span>]
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Vector</span>
    <span class="ruby-identifier">m</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">column_vector</span>(<span class="ruby-identifier">m</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Matrix</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">apply_through_coercion</span>(<span class="ruby-identifier">m</span>, <span class="ruby-identifier">__method__</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">row_count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">row_count</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">column_count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">column_count</span>

  <span class="ruby-identifier">rows</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">row_count</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">column_count</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">self</span>[<span class="ruby-identifier">i</span>, <span class="ruby-identifier">j</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">m</span>[<span class="ruby-identifier">i</span>, <span class="ruby-identifier">j</span>]
    }
  }
  <span class="ruby-identifier">new_matrix</span> <span class="ruby-identifier">rows</span>, <span class="ruby-identifier">column_count</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2B-40" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">+@</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="2B-40-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1283</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">+@</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">-</span><span
                                class="method-args">(m)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="Matrix.html"><code>Matrix</code></a> subtraction.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>,<span class="ruby-value">5</span>], [<span class="ruby-value">4</span>,<span class="ruby-value">2</span>]] <span class="ruby-operator">-</span> <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">9</span>,<span class="ruby-value">3</span>], [<span class="ruby-value">-4</span>,<span class="ruby-value">1</span>]]
<span class="ruby-comment">#  =&gt; -8  2</span>
<span class="ruby-comment">#      8  1</span>
</pre>

                              <div class="method-source-code" id="2D-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1120</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">-</span>(<span class="ruby-identifier">m</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">m</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Numeric</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrOperationNotDefined</span>, [<span class="ruby-string">&quot;-&quot;</span>, <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">m</span>.<span class="ruby-identifier">class</span>]
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Vector</span>
    <span class="ruby-identifier">m</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">column_vector</span>(<span class="ruby-identifier">m</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Matrix</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">apply_through_coercion</span>(<span class="ruby-identifier">m</span>, <span class="ruby-identifier">__method__</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">row_count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">row_count</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">column_count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">column_count</span>

  <span class="ruby-identifier">rows</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">row_count</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">column_count</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">self</span>[<span class="ruby-identifier">i</span>, <span class="ruby-identifier">j</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">m</span>[<span class="ruby-identifier">i</span>, <span class="ruby-identifier">j</span>]
    }
  }
  <span class="ruby-identifier">new_matrix</span> <span class="ruby-identifier">rows</span>, <span class="ruby-identifier">column_count</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2D-40" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">-@</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Unary matrix negation.</p>

<pre class="ruby"><span class="ruby-operator">-</span><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>,<span class="ruby-value">5</span>], [<span class="ruby-value">4</span>,<span class="ruby-value">2</span>]]
<span class="ruby-comment"># =&gt; -1 -5</span>
<span class="ruby-comment">#    -4 -2</span>
</pre>

                              <div class="method-source-code" id="2D-40-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1292</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">-@</span>
  <span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-operator">-</span><span class="ruby-identifier">e</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">/</span><span
                                class="method-args">(other)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="Matrix.html"><code>Matrix</code></a> division (multiplication by the inverse).</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">7</span>,<span class="ruby-value">6</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">9</span>]] <span class="ruby-operator">/</span> <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">2</span>,<span class="ruby-value">9</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">1</span>]]
<span class="ruby-comment">#  =&gt; -7  1</span>
<span class="ruby-comment">#     -3 -6</span>
</pre>

                              <div class="method-source-code" id="2F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1147</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">/</span>(<span class="ruby-identifier">other</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">other</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Numeric</span>
    <span class="ruby-identifier">rows</span> = <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">row</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">other</span> }
    }
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">new_matrix</span> <span class="ruby-identifier">rows</span>, <span class="ruby-identifier">column_count</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Matrix</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">inverse</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">apply_through_coercion</span>(<span class="ruby-identifier">other</span>, <span class="ruby-identifier">__method__</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-3D-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">==</span><span
                                class="method-args">(other)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns whether the two matrices contain equal elements.</p>

                              <div class="method-source-code" id="3D-3D-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1021</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">==</span>(<span class="ruby-identifier">other</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-constant">Matrix</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">other</span> <span class="ruby-operator">&amp;&amp;</span>
                      <span class="ruby-identifier">column_count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">column_count</span> <span class="ruby-comment"># necessary for empty matrices</span>
  <span class="ruby-identifier">rows</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">rows</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-5B-5D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">[]</span><span
                                class="method-args">(i, j)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns element (<code>i</code>,<code>j</code>) of the matrix.  That is: row <code>i</code>, column <code>j</code>.</p>

                              <div class="method-source-code" id="5B-5D-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 337</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">[]</span>(<span class="ruby-identifier">i</span>, <span class="ruby-identifier">j</span>)
  <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">i</span>){<span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>}[<span class="ruby-identifier">j</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-element">element</a>, <a href="Matrix.html#method-i-component">component</a>
                            </div>

                          </div>

                  <div id="method-i-5B-5D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          matrix[range, range] = matrix/element
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          matrix[range, integer] = vector/column_matrix/element
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          matrix[integer, range] = vector/row_matrix/element
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          matrix[integer, integer] = element
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Set element or elements of matrix.</p>

                              <div class="method-source-code" id="5B-5D-3D-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 351</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">[]=</span>(<span class="ruby-identifier">i</span>, <span class="ruby-identifier">j</span>, <span class="ruby-identifier">v</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">FrozenError</span>, <span class="ruby-string">&quot;can&#39;t modify frozen Matrix&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">frozen?</span>
  <span class="ruby-identifier">rows</span> = <span class="ruby-identifier">check_range</span>(<span class="ruby-identifier">i</span>, <span class="ruby-value">:row</span>) <span class="ruby-keyword">or</span> <span class="ruby-identifier">row</span> = <span class="ruby-identifier">check_int</span>(<span class="ruby-identifier">i</span>, <span class="ruby-value">:row</span>)
  <span class="ruby-identifier">columns</span> = <span class="ruby-identifier">check_range</span>(<span class="ruby-identifier">j</span>, <span class="ruby-value">:column</span>) <span class="ruby-keyword">or</span> <span class="ruby-identifier">column</span> = <span class="ruby-identifier">check_int</span>(<span class="ruby-identifier">j</span>, <span class="ruby-value">:column</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">rows</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">columns</span>
    <span class="ruby-identifier">set_row_and_col_range</span>(<span class="ruby-identifier">rows</span>, <span class="ruby-identifier">columns</span>, <span class="ruby-identifier">v</span>)
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">rows</span>
    <span class="ruby-identifier">set_row_range</span>(<span class="ruby-identifier">rows</span>, <span class="ruby-identifier">column</span>, <span class="ruby-identifier">v</span>)
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">columns</span>
    <span class="ruby-identifier">set_col_range</span>(<span class="ruby-identifier">row</span>, <span class="ruby-identifier">columns</span>, <span class="ruby-identifier">v</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">set_value</span>(<span class="ruby-identifier">row</span>, <span class="ruby-identifier">column</span>, <span class="ruby-identifier">v</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-set_element">set_element</a>, <a href="Matrix.html#method-i-set_component">set_component</a>
                            </div>

                          </div>

                  <div id="method-i-abs" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">abs</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the absolute value elementwise</p>

                              <div class="method-source-code" id="abs-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1299</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">abs</span>
  <span class="ruby-identifier">collect</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:abs</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-adjoint" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">adjoint</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the adjoint of the matrix.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[ [<span class="ruby-identifier">i</span>,<span class="ruby-value">1</span>],[<span class="ruby-value">2</span>,<span class="ruby-operator">-</span><span class="ruby-identifier">i</span>] ].<span class="ruby-identifier">adjoint</span>
<span class="ruby-comment">#  =&gt; -i 2</span>
<span class="ruby-comment">#      1 i</span>
</pre>

                              <div class="method-source-code" id="adjoint-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1595</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">adjoint</span>
  <span class="ruby-identifier">conjugate</span>.<span class="ruby-identifier">transpose</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-adjugate" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">adjugate</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the adjugate of the matrix.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[ [<span class="ruby-value">7</span>,<span class="ruby-value">6</span>],[<span class="ruby-value">3</span>,<span class="ruby-value">9</span>] ].<span class="ruby-identifier">adjugate</span>
<span class="ruby-comment">#  =&gt; 9 -6</span>
<span class="ruby-comment">#     -3 7</span>
</pre>

                              <div class="method-source-code" id="adjugate-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 793</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">adjugate</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">build</span>(<span class="ruby-identifier">row_count</span>, <span class="ruby-identifier">column_count</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">column</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">cofactor</span>(<span class="ruby-identifier">column</span>, <span class="ruby-identifier">row</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-antisymmetric-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">antisymmetric?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is an antisymmetric matrix. Raises an error if matrix is not square.</p>

                              <div class="method-source-code" id="antisymmetric-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 973</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">antisymmetric?</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  <span class="ruby-identifier">each_with_index</span>(<span class="ruby-value">:upper</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span>, <span class="ruby-identifier">row</span>, <span class="ruby-identifier">col</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">==</span> <span class="ruby-operator">-</span><span class="ruby-identifier">rows</span>[<span class="ruby-identifier">col</span>][<span class="ruby-identifier">row</span>]
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-skew_symmetric-3F">skew_symmetric?</a>
                            </div>

                          </div>

                  <div id="method-i-coerce" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">coerce</span><span
                                class="method-args">(other)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>The coerce method provides support for Ruby type coercion. This coercion mechanism is used by Ruby to handle mixed-type numeric operations: it is intended to find a compatible common type between the two operands of the operator. See also Numeric#coerce.</p>

                              <div class="method-source-code" id="coerce-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1648</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">coerce</span>(<span class="ruby-identifier">other</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">other</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Numeric</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">Scalar</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">other</span>), <span class="ruby-keyword">self</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">&quot;#{self.class} can&#39;t be coerced into #{other.class}&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-cofactor" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">cofactor</span><span
                                class="method-args">(row, column)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the (row, column) cofactor which is obtained by multiplying the first minor by (-1)**(row + column).</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">diagonal</span>(<span class="ruby-value">9</span>, <span class="ruby-value">5</span>, <span class="ruby-value">-3</span>, <span class="ruby-value">4</span>).<span class="ruby-identifier">cofactor</span>(<span class="ruby-value">1</span>, <span class="ruby-value">1</span>)
<span class="ruby-comment">#  =&gt; -108</span>
</pre>

                              <div class="method-source-code" id="cofactor-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 778</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">cofactor</span>(<span class="ruby-identifier">row</span>, <span class="ruby-identifier">column</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">RuntimeError</span>, <span class="ruby-string">&quot;cofactor of empty matrix is not defined&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">empty?</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>

  <span class="ruby-identifier">det_of_minor</span> = <span class="ruby-identifier">first_minor</span>(<span class="ruby-identifier">row</span>, <span class="ruby-identifier">column</span>).<span class="ruby-identifier">determinant</span>
  <span class="ruby-identifier">det_of_minor</span> <span class="ruby-operator">*</span> (<span class="ruby-value">-1</span>) <span class="ruby-operator">**</span> (<span class="ruby-identifier">row</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">column</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-cofactor_expansion" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">cofactor_expansion</span><span
                                class="method-args">(row: nil, column: nil)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-laplace_expansion">laplace_expansion</a>
                            </div>
                          </div>

                  <div id="method-i-collect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">collect</span><span
                                class="method-args">(which = :all) { |e| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a matrix that is the result of iteration of the given block over all elements of the matrix. Elements can be restricted by passing an argument:</p>
<ul><li>
<p>:all (default): yields all elements</p>
</li><li>
<p>:diagonal: yields only elements on the diagonal</p>
</li><li>
<p>:off_diagonal: yields all elements except on the diagonal</p>
</li><li>
<p>:lower: yields only elements on or below the diagonal</p>
</li><li>
<p>:strict_lower: yields only elements below the diagonal</p>
</li><li>
<p>:strict_upper: yields only elements above the diagonal</p>
</li><li>
<p>:upper: yields only elements on or above the diagonal Matrix[ [1,2], [3,4] ].collect { |e| e**2 } #  =&gt; 1  4 #     9 16</p>
</li></ul>

                              <div class="method-source-code" id="collect-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 508</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">collect</span>(<span class="ruby-identifier">which</span> = <span class="ruby-value">:all</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment"># :yield: e</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span>(<span class="ruby-value">:collect</span>, <span class="ruby-identifier">which</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
  <span class="ruby-identifier">dup</span>.<span class="ruby-identifier">collect!</span>(<span class="ruby-identifier">which</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-map">map</a>
                            </div>

                          </div>

                  <div id="method-i-collect-21" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">collect!</span><span
                                class="method-args">(which = :all) { |e| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Invokes the given block for each element of matrix, replacing the element with the value returned by the block. Elements can be restricted by passing an argument:</p>
<ul><li>
<p>:all (default): yields all elements</p>
</li><li>
<p>:diagonal: yields only elements on the diagonal</p>
</li><li>
<p>:off_diagonal: yields all elements except on the diagonal</p>
</li><li>
<p>:lower: yields only elements on or below the diagonal</p>
</li><li>
<p>:strict_lower: yields only elements below the diagonal</p>
</li><li>
<p>:strict_upper: yields only elements above the diagonal</p>
</li><li>
<p>:upper: yields only elements on or above the diagonal</p>
</li></ul>

                              <div class="method-source-code" id="collect-21-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 526</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">collect!</span>(<span class="ruby-identifier">which</span> = <span class="ruby-value">:all</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span>(<span class="ruby-value">:collect!</span>, <span class="ruby-identifier">which</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">FrozenError</span>, <span class="ruby-string">&quot;can&#39;t modify frozen Matrix&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">frozen?</span>
  <span class="ruby-identifier">each_with_index</span>(<span class="ruby-identifier">which</span>){ <span class="ruby-operator">|</span><span class="ruby-identifier">e</span>, <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@rows</span>[<span class="ruby-identifier">row_index</span>][<span class="ruby-identifier">col_index</span>] = <span class="ruby-keyword">yield</span> <span class="ruby-identifier">e</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-map-21">map!</a>
                            </div>

                          </div>

                  <div id="method-i-column" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">column</span><span
                                class="method-args">(j) { |e| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns column vector number <code>j</code> of the matrix as a <a href="Vector.html"><code>Vector</code></a> (starting at 0 like an array).  When a block is given, the elements of that vector are iterated.</p>

                              <div class="method-source-code" id="column-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 477</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">column</span>(<span class="ruby-identifier">j</span>) <span class="ruby-comment"># :yield: e</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">j</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-identifier">column_count</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">j</span> <span class="ruby-operator">&lt;</span> <span class="ruby-operator">-</span><span class="ruby-identifier">column_count</span>
    <span class="ruby-identifier">row_count</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">yield</span> <span class="ruby-ivar">@rows</span>[<span class="ruby-identifier">i</span>][<span class="ruby-identifier">j</span>]
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">self</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">j</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-identifier">column_count</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">j</span> <span class="ruby-operator">&lt;</span> <span class="ruby-operator">-</span><span class="ruby-identifier">column_count</span>
    <span class="ruby-identifier">col</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">row_count</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
      <span class="ruby-ivar">@rows</span>[<span class="ruby-identifier">i</span>][<span class="ruby-identifier">j</span>]
    }
    <span class="ruby-constant">Vector</span>.<span class="ruby-identifier">elements</span>(<span class="ruby-identifier">col</span>, <span class="ruby-keyword">false</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-column_vectors" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">column_vectors</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array of the column vectors of the matrix.  See <a href="Vector.html"><code>Vector</code></a>.</p>

                              <div class="method-source-code" id="column_vectors-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1669</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">column_vectors</span>
  <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">column_count</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">column</span>(<span class="ruby-identifier">i</span>)
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-combine" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          combine(*other_matrices) { |*elements| ... }
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates new matrix by combining with <em>other_matrices</em> entrywise, using the given block.</p>

<pre class="ruby"><span class="ruby-identifier">x</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">6</span>, <span class="ruby-value">6</span>], [<span class="ruby-value">4</span>, <span class="ruby-value">4</span>]]
<span class="ruby-identifier">y</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>], [<span class="ruby-value">3</span>, <span class="ruby-value">4</span>]]
<span class="ruby-identifier">x</span>.<span class="ruby-identifier">combine</span>(<span class="ruby-identifier">y</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">b</span>} <span class="ruby-comment"># =&gt; Matrix[[5, 4], [1, 0]]</span>
</pre>

                              <div class="method-source-code" id="combine-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 315</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">combine</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">matrices</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">combine</span>(<span class="ruby-keyword">self</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">matrices</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-component" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">component</span><span
                                class="method-args">(i, j)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-5B-5D">[]</a>
                            </div>
                          </div>

                  <div id="method-i-conj" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">conj</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-conjugate">conjugate</a>
                            </div>
                          </div>

                  <div id="method-i-conjugate" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">conjugate</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the conjugate of the matrix.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>,<span class="ruby-value">2</span>), <span class="ruby-constant">Complex</span>(<span class="ruby-value">0</span>,<span class="ruby-value">1</span>), <span class="ruby-value">0</span>], [<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>]]
<span class="ruby-comment">#  =&gt; 1+2i   i  0</span>
<span class="ruby-comment">#        1   2  3</span>
<span class="ruby-constant">Matrix</span>[[<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>,<span class="ruby-value">2</span>), <span class="ruby-constant">Complex</span>(<span class="ruby-value">0</span>,<span class="ruby-value">1</span>), <span class="ruby-value">0</span>], [<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>]].<span class="ruby-identifier">conjugate</span>
<span class="ruby-comment">#  =&gt; 1-2i  -i  0</span>
<span class="ruby-comment">#        1   2  3</span>
</pre>

                              <div class="method-source-code" id="conjugate-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1583</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">conjugate</span>
  <span class="ruby-identifier">collect</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:conjugate</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-conj">conj</a>
                            </div>

                          </div>

                  <div id="method-i-det" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">det</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-determinant">determinant</a>
                            </div>
                          </div>

                  <div id="method-i-det_e" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">det_e</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-determinant_e">determinant_e</a>
                            </div>
                          </div>

                  <div id="method-i-determinant" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">determinant</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the determinant of the matrix.</p>

<p>Beware that using Float values can yield erroneous results because of their lack of precision. Consider using exact types like Rational or BigDecimal instead.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">7</span>,<span class="ruby-value">6</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">9</span>]].<span class="ruby-identifier">determinant</span>
<span class="ruby-comment">#  =&gt; 45</span>
</pre>

                              <div class="method-source-code" id="determinant-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1317</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">determinant</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  <span class="ruby-identifier">m</span> = <span class="ruby-ivar">@rows</span>
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">row_count</span>
    <span class="ruby-comment"># Up to 4x4, give result using Laplacian expansion by minors.</span>
    <span class="ruby-comment"># This will typically be faster, as well as giving good results</span>
    <span class="ruby-comment"># in case of Floats</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">0</span>
    <span class="ruby-value">+1</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">1</span>
    <span class="ruby-operator">+</span> <span class="ruby-identifier">m</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>]
  <span class="ruby-keyword">when</span> <span class="ruby-value">2</span>
    <span class="ruby-operator">+</span> <span class="ruby-identifier">m</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m</span>[<span class="ruby-value">1</span>][<span class="ruby-value">1</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">m</span>[<span class="ruby-value">0</span>][<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m</span>[<span class="ruby-value">1</span>][<span class="ruby-value">0</span>]
  <span class="ruby-keyword">when</span> <span class="ruby-value">3</span>
    <span class="ruby-identifier">m0</span>, <span class="ruby-identifier">m1</span>, <span class="ruby-identifier">m2</span> = <span class="ruby-identifier">m</span>
    <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">1</span>] \
    <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">0</span>] \
    <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">0</span>]
  <span class="ruby-keyword">when</span> <span class="ruby-value">4</span>
    <span class="ruby-identifier">m0</span>, <span class="ruby-identifier">m1</span>, <span class="ruby-identifier">m2</span>, <span class="ruby-identifier">m3</span> = <span class="ruby-identifier">m</span>
    <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">2</span>] \
    <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">1</span>] \
    <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">1</span>] \
    <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">2</span>] \
    <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">0</span>] \
    <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">0</span>] \
    <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">1</span>] \
    <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">0</span>] \
    <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">0</span>] \
    <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">1</span>] \
    <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">0</span>] \
    <span class="ruby-operator">-</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">m0</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m1</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m2</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">m3</span>[<span class="ruby-value">0</span>]
  <span class="ruby-keyword">else</span>
    <span class="ruby-comment"># For bigger matrices, use an efficient and general algorithm.</span>
    <span class="ruby-comment"># Currently, we use the Gauss-Bareiss algorithm</span>
    <span class="ruby-identifier">determinant_bareiss</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-det">det</a>
                            </div>

                          </div>

                  <div id="method-i-determinant_e" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">determinant_e</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>deprecated; use <a href="Matrix.html#method-i-determinant"><code>Matrix#determinant</code></a></p>

                              <div class="method-source-code" id="determinant_e-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1398</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">determinant_e</span>
  <span class="ruby-identifier">warn</span> <span class="ruby-string">&quot;Matrix#determinant_e is deprecated; use #determinant&quot;</span>, <span class="ruby-value">uplevel:</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">determinant</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-det_e">det_e</a>
                            </div>

                          </div>

                  <div id="method-i-diagonal-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">diagonal?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is a diagonal matrix. Raises an error if matrix is not square.</p>

                              <div class="method-source-code" id="diagonal-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 839</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">diagonal?</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  <span class="ruby-identifier">each</span>(<span class="ruby-value">:off_diagonal</span>).<span class="ruby-identifier">all?</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:zero?</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each</span><span
                                class="method-args">(which = :all) { |e| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Yields all elements of the matrix, starting with those of the first row, or returns an Enumerator if no block given. Elements can be restricted by passing an argument:</p>
<ul><li>
<p>:all (default): yields all elements</p>
</li><li>
<p>:diagonal: yields only elements on the diagonal</p>
</li><li>
<p>:off_diagonal: yields all elements except on the diagonal</p>
</li><li>
<p>:lower: yields only elements on or below the diagonal</p>
</li><li>
<p>:strict_lower: yields only elements below the diagonal</p>
</li><li>
<p>:strict_upper: yields only elements above the diagonal</p>
</li><li>
<p>:upper: yields only elements on or above the diagonal</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[ [<span class="ruby-value">1</span>,<span class="ruby-value">2</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">4</span>] ].<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span> }
  <span class="ruby-comment"># =&gt; prints the numbers 1 to 4</span>
<span class="ruby-constant">Matrix</span>[ [<span class="ruby-value">1</span>,<span class="ruby-value">2</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">4</span>] ].<span class="ruby-identifier">each</span>(<span class="ruby-value">:strict_lower</span>).<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [3]</span>
</pre>
</li></ul>

                              <div class="method-source-code" id="each-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 556</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each</span>(<span class="ruby-identifier">which</span> = <span class="ruby-value">:all</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment"># :yield: e</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span> <span class="ruby-value">:each</span>, <span class="ruby-identifier">which</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
  <span class="ruby-identifier">last</span> = <span class="ruby-identifier">column_count</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">which</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:all</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">row</span>.<span class="ruby-identifier">each</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:diagonal</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">row_index</span>){<span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span>}
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:off_diagonal</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">column_count</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">col_index</span>] <span class="ruby-keyword">unless</span> <span class="ruby-identifier">row_index</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">col_index</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:lower</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      <span class="ruby-value">0</span>.<span class="ruby-identifier">upto</span>([<span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">last</span>].<span class="ruby-identifier">min</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">col_index</span>]
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:strict_lower</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      [<span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">column_count</span>].<span class="ruby-identifier">min</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">col_index</span>]
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:strict_upper</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      (<span class="ruby-identifier">row_index</span><span class="ruby-value">+1</span>).<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">last</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">col_index</span>]
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:upper</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">row_index</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">last</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">col_index</span>]
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_with_index" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each_with_index</span><span
                                class="method-args">(which = :all) { |e, row, column| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Same as <a href="Matrix.html#method-i-each"><code>each</code></a>, but the row index and column index in addition to the element</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[ [<span class="ruby-value">1</span>,<span class="ruby-value">2</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">4</span>] ].<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span>, <span class="ruby-identifier">row</span>, <span class="ruby-identifier">col</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;#{e} at #{row}, #{col}&quot;</span>
<span class="ruby-keyword">end</span>
  <span class="ruby-comment"># =&gt; Prints:</span>
  <span class="ruby-comment">#    1 at 0, 0</span>
  <span class="ruby-comment">#    2 at 0, 1</span>
  <span class="ruby-comment">#    3 at 1, 0</span>
  <span class="ruby-comment">#    4 at 1, 1</span>
</pre>

                              <div class="method-source-code" id="each_with_index-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 616</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_with_index</span>(<span class="ruby-identifier">which</span> = <span class="ruby-value">:all</span>) <span class="ruby-comment"># :yield: e, row, column</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span> <span class="ruby-value">:each_with_index</span>, <span class="ruby-identifier">which</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
  <span class="ruby-identifier">last</span> = <span class="ruby-identifier">column_count</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">which</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:all</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">row</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span>, <span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">e</span>, <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">col_index</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:diagonal</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">row_index</span>){<span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span>}, <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">row_index</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:off_diagonal</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">column_count</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">col_index</span>], <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">col_index</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">row_index</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">col_index</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:lower</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      <span class="ruby-value">0</span>.<span class="ruby-identifier">upto</span>([<span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">last</span>].<span class="ruby-identifier">min</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">col_index</span>], <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">col_index</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:strict_lower</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      [<span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">column_count</span>].<span class="ruby-identifier">min</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">col_index</span>], <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">col_index</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:strict_upper</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      (<span class="ruby-identifier">row_index</span><span class="ruby-value">+1</span>).<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">last</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">col_index</span>], <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">col_index</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:upper</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">row_index</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">row_index</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">last</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">col_index</span>], <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">col_index</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-eigen" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">eigen</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-eigensystem">eigensystem</a>
                            </div>
                          </div>

                  <div id="method-i-eigensystem" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">eigensystem</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the Eigensystem of the matrix; see <code>EigenvalueDecomposition</code>.</p>

<pre class="ruby"><span class="ruby-identifier">m</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>], [<span class="ruby-value">3</span>, <span class="ruby-value">4</span>]]
<span class="ruby-identifier">v</span>, <span class="ruby-identifier">d</span>, <span class="ruby-identifier">v_inv</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">eigensystem</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">diagonal?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">v</span>.<span class="ruby-identifier">inv</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">v_inv</span> <span class="ruby-comment"># =&gt; true</span>
(<span class="ruby-identifier">v</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">d</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">v_inv</span>).<span class="ruby-identifier">round</span>(<span class="ruby-value">5</span>) <span class="ruby-operator">==</span> <span class="ruby-identifier">m</span> <span class="ruby-comment"># =&gt; true</span>
</pre>

                              <div class="method-source-code" id="eigensystem-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1550</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">eigensystem</span>
  <span class="ruby-constant">EigenvalueDecomposition</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-eigen">eigen</a>
                            </div>

                          </div>

                  <div id="method-i-element" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">element</span><span
                                class="method-args">(i, j)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-5B-5D">[]</a>
                            </div>
                          </div>

                  <div id="method-i-elements_to_f" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">elements_to_f</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Deprecated.</p>

<p>Use <code>map(&amp;:to_f)</code></p>

                              <div class="method-source-code" id="elements_to_f-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1692</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">elements_to_f</span>
  <span class="ruby-identifier">warn</span> <span class="ruby-string">&quot;Matrix#elements_to_f is deprecated, use map(&amp;:to_f)&quot;</span>, <span class="ruby-value">uplevel:</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:to_f</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-elements_to_i" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">elements_to_i</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Deprecated.</p>

<p>Use <code>map(&amp;:to_i)</code></p>

                              <div class="method-source-code" id="elements_to_i-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1700</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">elements_to_i</span>
  <span class="ruby-identifier">warn</span> <span class="ruby-string">&quot;Matrix#elements_to_i is deprecated, use map(&amp;:to_i)&quot;</span>, <span class="ruby-value">uplevel:</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:to_i</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-elements_to_r" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">elements_to_r</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Deprecated.</p>

<p>Use <code>map(&amp;:to_r)</code></p>

                              <div class="method-source-code" id="elements_to_r-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1708</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">elements_to_r</span>
  <span class="ruby-identifier">warn</span> <span class="ruby-string">&quot;Matrix#elements_to_r is deprecated, use map(&amp;:to_r)&quot;</span>, <span class="ruby-value">uplevel:</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:to_r</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-empty-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">empty?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is an empty matrix, i.e. if the number of rows or the number of columns is 0.</p>

                              <div class="method-source-code" id="empty-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 848</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">empty?</span>
  <span class="ruby-identifier">column_count</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">row_count</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-entrywise_product" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">entrywise_product</span><span
                                class="method-args">(m)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-hadamard_product">hadamard_product</a>
                            </div>
                          </div>

                  <div id="method-i-eql-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">eql?</span><span
                                class="method-args">(other)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="eql-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1027</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">eql?</span>(<span class="ruby-identifier">other</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-constant">Matrix</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">other</span> <span class="ruby-operator">&amp;&amp;</span>
                      <span class="ruby-identifier">column_count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">column_count</span> <span class="ruby-comment"># necessary for empty matrices</span>
  <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">eql?</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">rows</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-find_index" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">find_index</span><span
                                class="method-args">(*args)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-index">index</a>
                            </div>
                          </div>

                  <div id="method-i-first_minor" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">first_minor</span><span
                                class="method-args">(row, column)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the submatrix obtained by deleting the specified row and column.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">diagonal</span>(<span class="ruby-value">9</span>, <span class="ruby-value">5</span>, <span class="ruby-value">-3</span>, <span class="ruby-value">4</span>).<span class="ruby-identifier">first_minor</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>)
<span class="ruby-comment">#  =&gt; 9 0 0</span>
<span class="ruby-comment">#     0 0 0</span>
<span class="ruby-comment">#     0 0 4</span>
</pre>

                              <div class="method-source-code" id="first_minor-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 751</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">first_minor</span>(<span class="ruby-identifier">row</span>, <span class="ruby-identifier">column</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">RuntimeError</span>, <span class="ruby-string">&quot;first_minor of empty matrix is not defined&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">empty?</span>

  <span class="ruby-keyword">unless</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">row</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">row</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">row_count</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;invalid row (#{row.inspect} for 0..#{row_count - 1})&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">unless</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">column</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">column</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">column_count</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;invalid column (#{column.inspect} for 0..#{column_count - 1})&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">arrays</span> = <span class="ruby-identifier">to_a</span>
  <span class="ruby-identifier">arrays</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">row</span>)
  <span class="ruby-identifier">arrays</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">array</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">array</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">column</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">new_matrix</span> <span class="ruby-identifier">arrays</span>, <span class="ruby-identifier">column_count</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-freeze" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">freeze</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="freeze-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 534</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">freeze</span>
  <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">each</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:freeze</span>).<span class="ruby-identifier">freeze</span>

  <span class="ruby-keyword">super</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-hadamard_product" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">hadamard_product</span><span
                                class="method-args">(m)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Hadamard product</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>,<span class="ruby-value">2</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">4</span>]].<span class="ruby-identifier">hadamard_product</span>(<span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>,<span class="ruby-value">2</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">2</span>]])
<span class="ruby-comment">#  =&gt; 1  4</span>
<span class="ruby-comment">#     9  8</span>
</pre>

                              <div class="method-source-code" id="hadamard_product-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1167</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hadamard_product</span>(<span class="ruby-identifier">m</span>)
  <span class="ruby-identifier">combine</span>(<span class="ruby-identifier">m</span>){<span class="ruby-operator">|</span><span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">b</span>}
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-entrywise_product">entrywise_product</a>
                            </div>

                          </div>

                  <div id="method-i-hash" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">hash</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a hash-code for the matrix.</p>

                              <div class="method-source-code" id="hash-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1044</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hash</span>
  <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">hash</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-hermitian-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">hermitian?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is an hermitian matrix. Raises an error if matrix is not square.</p>

                              <div class="method-source-code" id="hermitian-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 856</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hermitian?</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  <span class="ruby-identifier">each_with_index</span>(<span class="ruby-value">:upper</span>).<span class="ruby-identifier">all?</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span>, <span class="ruby-identifier">row</span>, <span class="ruby-identifier">col</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">e</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">rows</span>[<span class="ruby-identifier">col</span>][<span class="ruby-identifier">row</span>].<span class="ruby-identifier">conj</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-hstack" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">hstack</span><span
                                class="method-args">(*matrices)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new matrix resulting by stacking horizontally the receiver with the given matrices</p>

<pre class="ruby"><span class="ruby-identifier">x</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>], [<span class="ruby-value">3</span>, <span class="ruby-value">4</span>]]
<span class="ruby-identifier">y</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">5</span>, <span class="ruby-value">6</span>], [<span class="ruby-value">7</span>, <span class="ruby-value">8</span>]]
<span class="ruby-identifier">x</span>.<span class="ruby-identifier">hstack</span>(<span class="ruby-identifier">y</span>) <span class="ruby-comment"># =&gt; Matrix[[1, 2, 5, 6], [3, 4, 7, 8]]</span>
</pre>

                              <div class="method-source-code" id="hstack-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1412</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hstack</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">matrices</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">hstack</span>(<span class="ruby-keyword">self</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">matrices</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-imag" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">imag</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-imaginary">imaginary</a>
                            </div>
                          </div>

                  <div id="method-i-imaginary" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">imaginary</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the imaginary part of the matrix.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>,<span class="ruby-value">2</span>), <span class="ruby-constant">Complex</span>(<span class="ruby-value">0</span>,<span class="ruby-value">1</span>), <span class="ruby-value">0</span>], [<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>]]
<span class="ruby-comment">#  =&gt; 1+2i  i  0</span>
<span class="ruby-comment">#        1  2  3</span>
<span class="ruby-constant">Matrix</span>[[<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>,<span class="ruby-value">2</span>), <span class="ruby-constant">Complex</span>(<span class="ruby-value">0</span>,<span class="ruby-value">1</span>), <span class="ruby-value">0</span>], [<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>]].<span class="ruby-identifier">imaginary</span>
<span class="ruby-comment">#  =&gt;   2i  i  0</span>
<span class="ruby-comment">#        0  0  0</span>
</pre>

                              <div class="method-source-code" id="imaginary-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1608</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">imaginary</span>
  <span class="ruby-identifier">collect</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:imaginary</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-imag">imag</a>
                            </div>

                          </div>

                  <div id="method-i-index" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          index(value, selector = :all) &rarr; [row, column]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          index(selector = :all){ block } &rarr; [row, column]
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          index(selector = :all) &rarr; an_enumerator
                              </span>
                            </div>

                            <div class="method-description">
                              <p>The index method is specialized to return the index as [row, column] It also accepts an optional <code>selector</code> argument, see <a href="Matrix.html#method-i-each"><code>each</code></a> for details.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[ [<span class="ruby-value">1</span>,<span class="ruby-value">2</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">4</span>] ].<span class="ruby-identifier">index</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:even?</span>) <span class="ruby-comment"># =&gt; [0, 1]</span>
<span class="ruby-constant">Matrix</span>[ [<span class="ruby-value">1</span>,<span class="ruby-value">1</span>], [<span class="ruby-value">1</span>,<span class="ruby-value">1</span>] ].<span class="ruby-identifier">index</span>(<span class="ruby-value">1</span>, <span class="ruby-value">:strict_lower</span>) <span class="ruby-comment"># =&gt; [1, 0]</span>
</pre>

                              <div class="method-source-code" id="index-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 679</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">index</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;wrong number of arguments(#{args.size} for 0-2)&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">2</span>
  <span class="ruby-identifier">which</span> = (<span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">2</span> <span class="ruby-operator">||</span> <span class="ruby-constant">SELECTORS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">args</span>.<span class="ruby-identifier">last</span>)) <span class="ruby-operator">?</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">pop</span> <span class="ruby-operator">:</span> <span class="ruby-value">:all</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span> <span class="ruby-value">:find_index</span>, <span class="ruby-identifier">which</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
    <span class="ruby-identifier">value</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>
    <span class="ruby-identifier">each_with_index</span>(<span class="ruby-identifier">which</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span>, <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">col_index</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">value</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">each_with_index</span>(<span class="ruby-identifier">which</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span>, <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">col_index</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">row_index</span>, <span class="ruby-identifier">col_index</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">yield</span> <span class="ruby-identifier">e</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-find_index">find_index</a>
                            </div>

                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">inspect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Overrides Object#inspect</p>

                              <div class="method-source-code" id="inspect-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1733</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">inspect</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">empty?</span>
    <span class="ruby-node">&quot;#{self.class}.empty(#{row_count}, #{column_count})&quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-node">&quot;#{self.class}#{@rows.inspect}&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inv" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">inv</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-inverse">inverse</a>
                            </div>
                          </div>

                  <div id="method-i-inverse" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">inverse</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the inverse of the matrix.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">-1</span>, <span class="ruby-value">-1</span>], [<span class="ruby-value">0</span>, <span class="ruby-value">-1</span>]].<span class="ruby-identifier">inverse</span>
<span class="ruby-comment">#  =&gt; -1  1</span>
<span class="ruby-comment">#      0 -1</span>
</pre>

                              <div class="method-source-code" id="inverse-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1178</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">inverse</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-constant">I</span>(<span class="ruby-identifier">row_count</span>).<span class="ruby-identifier">send</span>(<span class="ruby-value">:inverse_from</span>, <span class="ruby-keyword">self</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-inv">inv</a>
                            </div>

                          </div>

                  <div id="method-i-laplace_expansion" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">laplace_expansion</span><span
                                class="method-args">(row: nil, column: nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the Laplace expansion along given row or column.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">7</span>,<span class="ruby-value">6</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">9</span>]].<span class="ruby-identifier">laplace_expansion</span>(<span class="ruby-value">column:</span> <span class="ruby-value">1</span>)
<span class="ruby-comment"># =&gt; 45</span>

<span class="ruby-constant">Matrix</span>[[<span class="ruby-constant">Vector</span>[<span class="ruby-value">1</span>, <span class="ruby-value">0</span>], <span class="ruby-constant">Vector</span>[<span class="ruby-value">0</span>, <span class="ruby-value">1</span>]], [<span class="ruby-value">2</span>, <span class="ruby-value">3</span>]].<span class="ruby-identifier">laplace_expansion</span>(<span class="ruby-value">row:</span> <span class="ruby-value">0</span>)
<span class="ruby-comment"># =&gt; Vector[3, -2]</span>
</pre>

                              <div class="method-source-code" id="laplace_expansion-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 810</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">laplace_expansion</span>(<span class="ruby-value">row:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">column:</span> <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">num</span> = <span class="ruby-identifier">row</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">column</span>

  <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">num</span> <span class="ruby-operator">||</span> (<span class="ruby-identifier">row</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">column</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;exactly one the row or column arguments must be specified&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">RuntimeError</span>, <span class="ruby-string">&quot;laplace_expansion of empty matrix is not defined&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">empty?</span>

  <span class="ruby-keyword">unless</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">num</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">num</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">row_count</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;invalid num (#{num.inspect} for 0..#{row_count - 1})&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">send</span>(<span class="ruby-identifier">row</span> <span class="ruby-operator">?</span> <span class="ruby-value">:row</span> <span class="ruby-operator">:</span> <span class="ruby-value">:column</span>, <span class="ruby-identifier">num</span>).<span class="ruby-identifier">map</span>.<span class="ruby-identifier">with_index</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span>, <span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">e</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">cofactor</span>(<span class="ruby-operator">*</span>(<span class="ruby-identifier">row</span> <span class="ruby-operator">?</span> [<span class="ruby-identifier">num</span>, <span class="ruby-identifier">k</span>] <span class="ruby-operator">:</span> [<span class="ruby-identifier">k</span>,<span class="ruby-identifier">num</span>]))
  }.<span class="ruby-identifier">inject</span>(<span class="ruby-value">:+</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-cofactor_expansion">cofactor_expansion</a>
                            </div>

                          </div>

                  <div id="method-i-lower_triangular-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">lower_triangular?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is a lower triangular matrix.</p>

                              <div class="method-source-code" id="lower_triangular-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 866</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">lower_triangular?</span>
  <span class="ruby-identifier">each</span>(<span class="ruby-value">:strict_upper</span>).<span class="ruby-identifier">all?</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:zero?</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-lup" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">lup</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the LUP decomposition of the matrix; see <code>LUPDecomposition</code>.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>], [<span class="ruby-value">3</span>, <span class="ruby-value">4</span>]]
<span class="ruby-identifier">l</span>, <span class="ruby-identifier">u</span>, <span class="ruby-identifier">p</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">lup</span>
<span class="ruby-identifier">l</span>.<span class="ruby-identifier">lower_triangular?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">u</span>.<span class="ruby-identifier">upper_triangular?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">p</span>.<span class="ruby-identifier">permutation?</span>      <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">l</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">u</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">p</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">a</span>      <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">lup</span>.<span class="ruby-identifier">solve</span>([<span class="ruby-value">2</span>, <span class="ruby-value">5</span>]) <span class="ruby-comment"># =&gt; Vector[(1/1), (1/2)]</span>
</pre>

                              <div class="method-source-code" id="lup-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1565</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">lup</span>
  <span class="ruby-constant">LUPDecomposition</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-lup_decomposition">lup_decomposition</a>
                            </div>

                          </div>

                  <div id="method-i-lup_decomposition" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">lup_decomposition</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-lup">lup</a>
                            </div>
                          </div>

                  <div id="method-i-map" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">map</span><span
                                class="method-args">(which = :all)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-collect">collect</a>
                            </div>
                          </div>

                  <div id="method-i-map-21" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">map!</span><span
                                class="method-args">(which = :all)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-collect-21">collect!</a>
                            </div>
                          </div>

                  <div id="method-i-minor" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">minor</span><span
                                class="method-args">(*param)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a section of the matrix.  The parameters are either:</p>
<ul><li>
<p>start_row, nrows, start_col, ncols; OR</p>
</li><li>
<p>row_range, col_range</p>
</li></ul>

<pre class="ruby"><span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">diagonal</span>(<span class="ruby-value">9</span>, <span class="ruby-value">5</span>, <span class="ruby-value">-3</span>).<span class="ruby-identifier">minor</span>(<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>, <span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>)
<span class="ruby-comment">#  =&gt; 9 0 0</span>
<span class="ruby-comment">#     0 5 0</span>
</pre>

<p>Like Array#[], negative indices count backward from the end of the row or column (-1 is the last element). Returns nil if the starting row or column is greater than <a href="Matrix.html#method-i-row_count"><code>row_count</code></a> or <a href="Matrix.html#attribute-i-column_count"><code>column_count</code></a> respectively.</p>

                              <div class="method-source-code" id="minor-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 710</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">minor</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">param</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">param</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">2</span>
    <span class="ruby-identifier">row_range</span>, <span class="ruby-identifier">col_range</span> = <span class="ruby-identifier">param</span>
    <span class="ruby-identifier">from_row</span> = <span class="ruby-identifier">row_range</span>.<span class="ruby-identifier">first</span>
    <span class="ruby-identifier">from_row</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">row_count</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">from_row</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">to_row</span> = <span class="ruby-identifier">row_range</span>.<span class="ruby-identifier">end</span>
    <span class="ruby-identifier">to_row</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">row_count</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">to_row</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">to_row</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">row_range</span>.<span class="ruby-identifier">exclude_end?</span>
    <span class="ruby-identifier">size_row</span> = <span class="ruby-identifier">to_row</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">from_row</span>

    <span class="ruby-identifier">from_col</span> = <span class="ruby-identifier">col_range</span>.<span class="ruby-identifier">first</span>
    <span class="ruby-identifier">from_col</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">column_count</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">from_col</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">to_col</span> = <span class="ruby-identifier">col_range</span>.<span class="ruby-identifier">end</span>
    <span class="ruby-identifier">to_col</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">column_count</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">to_col</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">to_col</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">col_range</span>.<span class="ruby-identifier">exclude_end?</span>
    <span class="ruby-identifier">size_col</span> = <span class="ruby-identifier">to_col</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">from_col</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">4</span>
    <span class="ruby-identifier">from_row</span>, <span class="ruby-identifier">size_row</span>, <span class="ruby-identifier">from_col</span>, <span class="ruby-identifier">size_col</span> = <span class="ruby-identifier">param</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">size_row</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">size_col</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">from_row</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">row_count</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">from_row</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">from_col</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">column_count</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">from_col</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-identifier">param</span>.<span class="ruby-identifier">inspect</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">from_row</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">row_count</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">from_col</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">column_count</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">from_row</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">from_col</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
  <span class="ruby-identifier">rows</span> = <span class="ruby-ivar">@rows</span>[<span class="ruby-identifier">from_row</span>, <span class="ruby-identifier">size_row</span>].<span class="ruby-identifier">collect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">row</span>[<span class="ruby-identifier">from_col</span>, <span class="ruby-identifier">size_col</span>]
  }
  <span class="ruby-identifier">new_matrix</span> <span class="ruby-identifier">rows</span>, [<span class="ruby-identifier">column_count</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">from_col</span>, <span class="ruby-identifier">size_col</span>].<span class="ruby-identifier">min</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-normal-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">normal?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is a normal matrix. Raises an error if matrix is not square.</p>

                              <div class="method-source-code" id="normal-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 874</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">normal?</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row_i</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row_j</span>, <span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">s</span> = <span class="ruby-value">0</span>
      <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row_k</span>, <span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">s</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">row_i</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">row_j</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">conj</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">row_k</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">conj</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">row_k</span>[<span class="ruby-identifier">j</span>]
      <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">s</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-orthogonal-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">orthogonal?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is an orthogonal matrix Raises an error if matrix is not square.</p>

                              <div class="method-source-code" id="orthogonal-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 892</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">orthogonal?</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>

  <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row_i</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row_j</span>, <span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">s</span> = <span class="ruby-value">0</span>
      <span class="ruby-identifier">row_count</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">s</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">row_i</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">row_j</span>[<span class="ruby-identifier">k</span>]
      <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">s</span> <span class="ruby-operator">==</span> (<span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">j</span> <span class="ruby-operator">?</span> <span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-value">0</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-permutation-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">permutation?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is a permutation matrix Raises an error if matrix is not square.</p>

                              <div class="method-source-code" id="permutation-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 911</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">permutation?</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  <span class="ruby-identifier">cols</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">column_count</span>)
  <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">found</span> = <span class="ruby-keyword">false</span>
    <span class="ruby-identifier">row</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span>, <span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
        <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">found</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">cols</span>[<span class="ruby-identifier">j</span>]
        <span class="ruby-identifier">found</span> = <span class="ruby-identifier">cols</span>[<span class="ruby-identifier">j</span>] = <span class="ruby-keyword">true</span>
      <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
        <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">found</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rank" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">rank</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the rank of the matrix. Beware that using Float values can yield erroneous results because of their lack of precision. Consider using exact types like Rational or BigDecimal instead.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">7</span>,<span class="ruby-value">6</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">9</span>]].<span class="ruby-identifier">rank</span>
<span class="ruby-comment">#  =&gt; 2</span>
</pre>

                              <div class="method-source-code" id="rank-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1425</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">rank</span>
  <span class="ruby-comment"># We currently use Bareiss&#39; multistep integer-preserving gaussian elimination</span>
  <span class="ruby-comment"># (see comments on determinant)</span>
  <span class="ruby-identifier">a</span> = <span class="ruby-identifier">to_a</span>
  <span class="ruby-identifier">last_column</span> = <span class="ruby-identifier">column_count</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">last_row</span> = <span class="ruby-identifier">row_count</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">pivot_row</span> = <span class="ruby-value">0</span>
  <span class="ruby-identifier">previous_pivot</span> = <span class="ruby-value">1</span>
  <span class="ruby-value">0</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">last_column</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">switch_row</span> = (<span class="ruby-identifier">pivot_row</span> <span class="ruby-operator">..</span> <span class="ruby-identifier">last_row</span>).<span class="ruby-identifier">find</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">a</span>[<span class="ruby-identifier">row</span>][<span class="ruby-identifier">k</span>] <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
    }
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">switch_row</span>
      <span class="ruby-identifier">a</span>[<span class="ruby-identifier">switch_row</span>], <span class="ruby-identifier">a</span>[<span class="ruby-identifier">pivot_row</span>] = <span class="ruby-identifier">a</span>[<span class="ruby-identifier">pivot_row</span>], <span class="ruby-identifier">a</span>[<span class="ruby-identifier">switch_row</span>] <span class="ruby-keyword">unless</span> <span class="ruby-identifier">pivot_row</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">switch_row</span>
      <span class="ruby-identifier">pivot</span> = <span class="ruby-identifier">a</span>[<span class="ruby-identifier">pivot_row</span>][<span class="ruby-identifier">k</span>]
      (<span class="ruby-identifier">pivot_row</span><span class="ruby-value">+1</span>).<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">last_row</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
         <span class="ruby-identifier">ai</span> = <span class="ruby-identifier">a</span>[<span class="ruby-identifier">i</span>]
         (<span class="ruby-identifier">k</span><span class="ruby-value">+1</span>).<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">last_column</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
           <span class="ruby-identifier">ai</span>[<span class="ruby-identifier">j</span>] =  (<span class="ruby-identifier">pivot</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">ai</span>[<span class="ruby-identifier">j</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">ai</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">a</span>[<span class="ruby-identifier">pivot_row</span>][<span class="ruby-identifier">j</span>]) <span class="ruby-operator">/</span> <span class="ruby-identifier">previous_pivot</span>
         <span class="ruby-keyword">end</span>
       <span class="ruby-keyword">end</span>
      <span class="ruby-identifier">pivot_row</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
      <span class="ruby-identifier">previous_pivot</span> = <span class="ruby-identifier">pivot</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">pivot_row</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rank_e" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">rank_e</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>deprecated; use <a href="Matrix.html#method-i-rank"><code>Matrix#rank</code></a></p>

                              <div class="method-source-code" id="rank_e-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1456</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">rank_e</span>
  <span class="ruby-identifier">warn</span> <span class="ruby-string">&quot;Matrix#rank_e is deprecated; use #rank&quot;</span>, <span class="ruby-value">uplevel:</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">rank</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-real" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">real</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the real part of the matrix.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>,<span class="ruby-value">2</span>), <span class="ruby-constant">Complex</span>(<span class="ruby-value">0</span>,<span class="ruby-value">1</span>), <span class="ruby-value">0</span>], [<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>]]
<span class="ruby-comment">#  =&gt; 1+2i  i  0</span>
<span class="ruby-comment">#        1  2  3</span>
<span class="ruby-constant">Matrix</span>[[<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>,<span class="ruby-value">2</span>), <span class="ruby-constant">Complex</span>(<span class="ruby-value">0</span>,<span class="ruby-value">1</span>), <span class="ruby-value">0</span>], [<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>]].<span class="ruby-identifier">real</span>
<span class="ruby-comment">#  =&gt;    1  0  0</span>
<span class="ruby-comment">#        1  2  3</span>
</pre>

                              <div class="method-source-code" id="real-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1622</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">real</span>
  <span class="ruby-identifier">collect</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:real</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-real-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">real?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if all entries of the matrix are real.</p>

                              <div class="method-source-code" id="real-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 932</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">real?</span>
  <span class="ruby-identifier">all?</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:real?</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">rect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array containing matrices corresponding to the real and imaginary parts of the matrix</p>

<pre class="ruby"><span class="ruby-identifier">m</span>.<span class="ruby-identifier">rect</span> <span class="ruby-operator">==</span> [<span class="ruby-identifier">m</span>.<span class="ruby-identifier">real</span>, <span class="ruby-identifier">m</span>.<span class="ruby-identifier">imag</span>]  <span class="ruby-comment"># ==&gt; true for all matrices m</span>
</pre>

                              <div class="method-source-code" id="rect-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1632</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">rect</span>
  [<span class="ruby-identifier">real</span>, <span class="ruby-identifier">imag</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-rectangular">rectangular</a>
                            </div>

                          </div>

                  <div id="method-i-rectangular" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">rectangular</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-rect">rect</a>
                            </div>
                          </div>

                  <div id="method-i-regular-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">regular?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is a regular (i.e. non-singular) matrix.</p>

                              <div class="method-source-code" id="regular-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 939</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">regular?</span>
  <span class="ruby-keyword">not</span> <span class="ruby-identifier">singular?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rotate_entries" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">rotate_entries</span><span
                                class="method-args">(rotation = :clockwise)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new matrix with rotated elements. The argument specifies the rotation (defaults to ‘:clockwise`):</p>
<ul><li>
<p>:clockwise, 1, -3, etc.: “turn right” - first row becomes last column</p>
</li><li>
<p>:half_turn, 2, -2, etc.: first row becomes last row, elements in reverse order</p>
</li><li>
<p>:counter_clockwise, -1, 3: “turn left” - first row becomes first column (but with elements in reverse order)</p>

<p>m = Matrix[ [1, 2], [3, 4] ] r = m.rotate_entries(:clockwise) #  =&gt; Matrix[[3, 1], [4, 2]]</p>
</li></ul>

                              <div class="method-source-code" id="rotate_entries-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1473</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">rotate_entries</span>(<span class="ruby-identifier">rotation</span> = <span class="ruby-value">:clockwise</span>)
  <span class="ruby-identifier">rotation</span> <span class="ruby-operator">%=</span> <span class="ruby-value">4</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">rotation</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value">:to_int</span>

  <span class="ruby-keyword">case</span> <span class="ruby-identifier">rotation</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">dup</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">1</span>, <span class="ruby-value">:clockwise</span>
    <span class="ruby-identifier">new_matrix</span> <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">transpose</span>.<span class="ruby-identifier">each</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:reverse!</span>), <span class="ruby-identifier">row_count</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">2</span>, <span class="ruby-value">:half_turn</span>
    <span class="ruby-identifier">new_matrix</span> <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:reverse</span>).<span class="ruby-identifier">reverse!</span>, <span class="ruby-identifier">column_count</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">3</span>, <span class="ruby-value">:counter_clockwise</span>
    <span class="ruby-identifier">new_matrix</span> <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">transpose</span>.<span class="ruby-identifier">reverse!</span>, <span class="ruby-identifier">row_count</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;expected #{rotation.inspect} to be one of :clockwise, :counter_clockwise, :half_turn or an integer&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-round" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">round</span><span
                                class="method-args">(ndigits=0)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a matrix with entries rounded to the given precision (see Float#round)</p>

                              <div class="method-source-code" id="round-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1493</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">round</span>(<span class="ruby-identifier">ndigits</span>=<span class="ruby-value">0</span>)
  <span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">round</span>(<span class="ruby-identifier">ndigits</span>)}
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-row" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">row</span><span
                                class="method-args">(i) { |e| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns row vector number <code>i</code> of the matrix as a <a href="Vector.html"><code>Vector</code></a> (starting at 0 like an array).  When a block is given, the elements of that vector are iterated.</p>

                              <div class="method-source-code" id="row-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 463</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">row</span>(<span class="ruby-identifier">i</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment"># :yield: e</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
    <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">i</span>){<span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span>}.<span class="ruby-identifier">each</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
    <span class="ruby-keyword">self</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-constant">Vector</span>.<span class="ruby-identifier">elements</span>(<span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">i</span>){<span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>})
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-row_count" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">row_count</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the number of rows.</p>

                              <div class="method-source-code" id="row_count-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 448</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">row_count</span>
  <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">size</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-row_size">row_size</a>
                            </div>

                          </div>

                  <div id="method-i-row_size" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">row_size</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-row_count">row_count</a>
                            </div>
                          </div>

                  <div id="method-i-row_vectors" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">row_vectors</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array of the row vectors of the matrix.  See <a href="Vector.html"><code>Vector</code></a>.</p>

                              <div class="method-source-code" id="row_vectors-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1660</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">row_vectors</span>
  <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">row_count</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">row</span>(<span class="ruby-identifier">i</span>)
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-singular-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">singular?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is a singular matrix.</p>

                              <div class="method-source-code" id="singular-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 946</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">singular?</span>
  <span class="ruby-identifier">determinant</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-skew_symmetric-3F" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">skew_symmetric?</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-antisymmetric-3F">antisymmetric?</a>
                            </div>
                          </div>

                  <div id="method-i-square-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">square?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is a square matrix.</p>

                              <div class="method-source-code" id="square-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 953</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">square?</span>
  <span class="ruby-identifier">column_count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">row_count</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-symmetric-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">symmetric?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is a symmetric matrix. Raises an error if matrix is not square.</p>

                              <div class="method-source-code" id="symmetric-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 961</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">symmetric?</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  <span class="ruby-identifier">each_with_index</span>(<span class="ruby-value">:strict_upper</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span>, <span class="ruby-identifier">row</span>, <span class="ruby-identifier">col</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">rows</span>[<span class="ruby-identifier">col</span>][<span class="ruby-identifier">row</span>]
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-t" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">t</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-transpose">transpose</a>
                            </div>
                          </div>

                  <div id="method-i-to_a" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">to_a</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array of arrays that describe the rows of the matrix.</p>

                              <div class="method-source-code" id="to_a-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1685</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_a</span>
  <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">collect</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:dup</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_matrix" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">to_matrix</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Explicit conversion to a <a href="Matrix.html"><code>Matrix</code></a>. Returns self</p>

                              <div class="method-source-code" id="to_matrix-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1678</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_matrix</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_s" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">to_s</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Overrides Object#to_s</p>

                              <div class="method-source-code" id="to_s-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1720</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_s</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">empty?</span>
    <span class="ruby-node">&quot;#{self.class}.empty(#{row_count}, #{column_count})&quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-node">&quot;#{self.class}[&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">collect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
      <span class="ruby-string">&quot;[&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">collect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span>}.<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;, &quot;</span>) <span class="ruby-operator">+</span> <span class="ruby-string">&quot;]&quot;</span>
    }.<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;, &quot;</span>)<span class="ruby-string">+&quot;]&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-tr" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">tr</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-trace">trace</a>
                            </div>
                          </div>

                  <div id="method-i-trace" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">trace</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the trace (sum of diagonal elements) of the matrix.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">7</span>,<span class="ruby-value">6</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">9</span>]].<span class="ruby-identifier">trace</span>
<span class="ruby-comment">#  =&gt; 16</span>
</pre>

                              <div class="method-source-code" id="trace-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1502</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">trace</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  (<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">column_count</span>).<span class="ruby-identifier">inject</span>(<span class="ruby-value">0</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">tr</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">tr</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@rows</span>[<span class="ruby-identifier">i</span>][<span class="ruby-identifier">i</span>]
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-tr">tr</a>
                            </div>

                          </div>

                  <div id="method-i-transpose" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">transpose</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the transpose of the matrix.</p>

<pre class="ruby"><span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>,<span class="ruby-value">2</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">4</span>], [<span class="ruby-value">5</span>,<span class="ruby-value">6</span>]]
<span class="ruby-comment">#  =&gt; 1 2</span>
<span class="ruby-comment">#     3 4</span>
<span class="ruby-comment">#     5 6</span>
<span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>,<span class="ruby-value">2</span>], [<span class="ruby-value">3</span>,<span class="ruby-value">4</span>], [<span class="ruby-value">5</span>,<span class="ruby-value">6</span>]].<span class="ruby-identifier">transpose</span>
<span class="ruby-comment">#  =&gt; 1 3 5</span>
<span class="ruby-comment">#     2 4 6</span>
</pre>

                              <div class="method-source-code" id="transpose-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1520</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">transpose</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">empty</span>(<span class="ruby-identifier">column_count</span>, <span class="ruby-value">0</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">row_count</span>.<span class="ruby-identifier">zero?</span>
  <span class="ruby-identifier">new_matrix</span> <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">transpose</span>, <span class="ruby-identifier">row_count</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Matrix.html#method-i-t">t</a>
                            </div>

                          </div>

                  <div id="method-i-unitary-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">unitary?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is a unitary matrix Raises an error if matrix is not square.</p>

                              <div class="method-source-code" id="unitary-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 986</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">unitary?</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">square?</span>
  <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row_i</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row_j</span>, <span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">s</span> = <span class="ruby-value">0</span>
      <span class="ruby-identifier">row_count</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">s</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">row_i</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">conj</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">row_j</span>[<span class="ruby-identifier">k</span>]
      <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">s</span> <span class="ruby-operator">==</span> (<span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">j</span> <span class="ruby-operator">?</span> <span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-value">0</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-upper_triangular-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">upper_triangular?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is an upper triangular matrix.</p>

                              <div class="method-source-code" id="upper_triangular-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1003</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">upper_triangular?</span>
  <span class="ruby-identifier">each</span>(<span class="ruby-value">:strict_lower</span>).<span class="ruby-identifier">all?</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:zero?</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-vstack" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">vstack</span><span
                                class="method-args">(*matrices)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new matrix resulting by stacking vertically the receiver with the given matrices</p>

<pre class="ruby"><span class="ruby-identifier">x</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>], [<span class="ruby-value">3</span>, <span class="ruby-value">4</span>]]
<span class="ruby-identifier">y</span> = <span class="ruby-constant">Matrix</span>[[<span class="ruby-value">5</span>, <span class="ruby-value">6</span>], [<span class="ruby-value">7</span>, <span class="ruby-value">8</span>]]
<span class="ruby-identifier">x</span>.<span class="ruby-identifier">vstack</span>(<span class="ruby-identifier">y</span>) <span class="ruby-comment"># =&gt; Matrix[[1, 2], [3, 4], [5, 6], [7, 8]]</span>
</pre>

                              <div class="method-source-code" id="vstack-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1534</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">vstack</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">matrices</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">vstack</span>(<span class="ruby-keyword">self</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">matrices</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-zero-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">zero?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is a matrix with only zero elements</p>

                              <div class="method-source-code" id="zero-3F-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1010</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">zero?</span>
  <span class="ruby-identifier">all?</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:zero?</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="protected-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Protected Instance Methods</h3>
                </header>

                  <div id="method-i-power_int" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">power_int</span><span
                                class="method-args">(exp)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="power_int-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1257</span>
          <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">power_int</span>(<span class="ruby-identifier">exp</span>)
  <span class="ruby-comment"># assumes `exp` is an Integer &gt; 0</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Previous algorithm:</span>
  <span class="ruby-comment">#   build M**2, M**4 = (M**2)**2, M**8, ... and multiplying those you need</span>
  <span class="ruby-comment">#   e.g. M**0b1011 = M**11 = M * M**2 * M**8</span>
  <span class="ruby-comment">#                              ^  ^</span>
  <span class="ruby-comment">#   (highlighted the 2 out of 5 multiplications involving `M * x`)</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Current algorithm has same number of multiplications but with lower exponents:</span>
  <span class="ruby-comment">#    M**11 = M * (M * M**4)**2</span>
  <span class="ruby-comment">#              ^    ^  ^</span>
  <span class="ruby-comment">#   (highlighted the 3 out of 5 multiplications involving `M * x`)</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># This should be faster for all (non nil-potent) matrices.</span>
  <span class="ruby-keyword">case</span>
  <span class="ruby-keyword">when</span> <span class="ruby-identifier">exp</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
    <span class="ruby-keyword">self</span>
  <span class="ruby-keyword">when</span> <span class="ruby-identifier">exp</span>.<span class="ruby-identifier">odd?</span>
    <span class="ruby-keyword">self</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">power_int</span>(<span class="ruby-identifier">exp</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">sqrt</span> = <span class="ruby-identifier">power_int</span>(<span class="ruby-identifier">exp</span> <span class="ruby-operator">/</span> <span class="ruby-value">2</span>)
    <span class="ruby-identifier">sqrt</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">sqrt</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-check_int" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">check_int</span><span
                                class="method-args">(val, direction)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="check_int-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 376</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">check_int</span>(<span class="ruby-identifier">val</span>, <span class="ruby-identifier">direction</span>)
  <span class="ruby-identifier">count</span> = <span class="ruby-identifier">direction</span> <span class="ruby-operator">==</span> <span class="ruby-value">:row</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">row_count</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">column_count</span>
  <span class="ruby-constant">CoercionHelper</span>.<span class="ruby-identifier">check_int</span>(<span class="ruby-identifier">val</span>, <span class="ruby-identifier">count</span>, <span class="ruby-identifier">direction</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-check_range" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">check_range</span><span
                                class="method-args">(val, direction)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns range or nil</p>

                              <div class="method-source-code" id="check_range-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 370</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">check_range</span>(<span class="ruby-identifier">val</span>, <span class="ruby-identifier">direction</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Range</span>)
  <span class="ruby-identifier">count</span> = <span class="ruby-identifier">direction</span> <span class="ruby-operator">==</span> <span class="ruby-value">:row</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">row_count</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">column_count</span>
  <span class="ruby-constant">CoercionHelper</span>.<span class="ruby-identifier">check_range</span>(<span class="ruby-identifier">val</span>, <span class="ruby-identifier">count</span>, <span class="ruby-identifier">direction</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-determinant_bareiss" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">determinant_bareiss</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Private. Use <a href="Matrix.html#method-i-determinant"><code>Matrix#determinant</code></a></p>

<p>Returns the determinant of the matrix, using Bareiss’ multistep integer-preserving gaussian elimination. It has the same computational cost order O(n^3) as standard Gaussian elimination. Intermediate results are fraction free and of lower complexity. A matrix of Integers will have thus intermediate results that are also Integers, with smaller bignums (if any), while a matrix of Float will usually have intermediate results with better precision.</p>

                              <div class="method-source-code" id="determinant_bareiss-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1368</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">determinant_bareiss</span>
  <span class="ruby-identifier">size</span> = <span class="ruby-identifier">row_count</span>
  <span class="ruby-identifier">last</span> = <span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">a</span> = <span class="ruby-identifier">to_a</span>
  <span class="ruby-identifier">no_pivot</span> = <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span>{ <span class="ruby-keyword">return</span> <span class="ruby-value">0</span> }
  <span class="ruby-identifier">sign</span> = <span class="ruby-value">+1</span>
  <span class="ruby-identifier">pivot</span> = <span class="ruby-value">1</span>
  <span class="ruby-identifier">size</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">previous_pivot</span> = <span class="ruby-identifier">pivot</span>
    <span class="ruby-keyword">if</span> (<span class="ruby-identifier">pivot</span> = <span class="ruby-identifier">a</span>[<span class="ruby-identifier">k</span>][<span class="ruby-identifier">k</span>]) <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
      <span class="ruby-identifier">switch</span> = (<span class="ruby-identifier">k</span><span class="ruby-value">+1</span> <span class="ruby-operator">...</span> <span class="ruby-identifier">size</span>).<span class="ruby-identifier">find</span>(<span class="ruby-identifier">no_pivot</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">a</span>[<span class="ruby-identifier">row</span>][<span class="ruby-identifier">k</span>] <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
      }
      <span class="ruby-identifier">a</span>[<span class="ruby-identifier">switch</span>], <span class="ruby-identifier">a</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">a</span>[<span class="ruby-identifier">k</span>], <span class="ruby-identifier">a</span>[<span class="ruby-identifier">switch</span>]
      <span class="ruby-identifier">pivot</span> = <span class="ruby-identifier">a</span>[<span class="ruby-identifier">k</span>][<span class="ruby-identifier">k</span>]
      <span class="ruby-identifier">sign</span> = <span class="ruby-operator">-</span><span class="ruby-identifier">sign</span>
    <span class="ruby-keyword">end</span>
    (<span class="ruby-identifier">k</span><span class="ruby-value">+1</span>).<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">last</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">ai</span> = <span class="ruby-identifier">a</span>[<span class="ruby-identifier">i</span>]
      (<span class="ruby-identifier">k</span><span class="ruby-value">+1</span>).<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">last</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">ai</span>[<span class="ruby-identifier">j</span>] =  (<span class="ruby-identifier">pivot</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">ai</span>[<span class="ruby-identifier">j</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">ai</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">a</span>[<span class="ruby-identifier">k</span>][<span class="ruby-identifier">j</span>]) <span class="ruby-operator">/</span> <span class="ruby-identifier">previous_pivot</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">sign</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">pivot</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-initialize_copy" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">initialize_copy</span><span
                                class="method-args">(m)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Called for dup &amp; clone.</p>
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="initialize_copy-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 1036</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize_copy</span>(<span class="ruby-identifier">m</span>)
  <span class="ruby-keyword">super</span>
  <span class="ruby-ivar">@rows</span> = <span class="ruby-ivar">@rows</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:dup</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">frozen?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-set_col_range" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">set_col_range</span><span
                                class="method-args">(row, col_range, value)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="set_col_range-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 432</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_col_range</span>(<span class="ruby-identifier">row</span>, <span class="ruby-identifier">col_range</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">value</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Vector</span>)
    <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_a</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Matrix</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">row_count</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
    <span class="ruby-identifier">value</span>.<span class="ruby-identifier">row</span>(<span class="ruby-value">0</span>).<span class="ruby-identifier">to_a</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">col_range</span>.<span class="ruby-identifier">size</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">col_range</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-ivar">@rows</span>[<span class="ruby-identifier">row</span>][<span class="ruby-identifier">col_range</span>] = <span class="ruby-identifier">value</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-set_column_vector" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">set_column_vector</span><span
                                class="method-args">(row_range, col, value)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="set_column_vector-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 425</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_column_vector</span>(<span class="ruby-identifier">row_range</span>, <span class="ruby-identifier">col</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">value</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">r</span> = <span class="ruby-identifier">row_range</span>.<span class="ruby-identifier">begin</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">index</span>
    <span class="ruby-ivar">@rows</span>[<span class="ruby-identifier">r</span>][<span class="ruby-identifier">col</span>] = <span class="ruby-identifier">e</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-set_component" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">set_component</span><span
                                class="method-args">(i, j, v)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-5B-5D-3D">[]=</a>
                            </div>
                          </div>

                  <div id="method-i-set_element" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">set_element</span><span
                                class="method-args">(i, j, v)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Matrix.html#method-i-5B-5D-3D">[]=</a>
                            </div>
                          </div>

                  <div id="method-i-set_row_and_col_range" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">set_row_and_col_range</span><span
                                class="method-args">(row_range, col_range, value)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="set_row_and_col_range-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 387</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_row_and_col_range</span>(<span class="ruby-identifier">row_range</span>, <span class="ruby-identifier">col_range</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Matrix</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">row_range</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">row_count</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">col_range</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">column_count</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span>, [
        <span class="ruby-string">&#39;Expected a Matrix of dimensions&#39;</span>,
        <span class="ruby-node">&quot;#{row_range.size}x#{col_range.size}&quot;</span>,
        <span class="ruby-string">&#39;got&#39;</span>,
        <span class="ruby-node">&quot;#{value.row_count}x#{value.column_count}&quot;</span>,
      ].<span class="ruby-identifier">join</span>(<span class="ruby-string">&#39; &#39;</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">source</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">instance_variable_get</span> <span class="ruby-value">:@rows</span>
    <span class="ruby-identifier">row_range</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
      <span class="ruby-ivar">@rows</span>[<span class="ruby-identifier">row</span>][<span class="ruby-identifier">col_range</span>] = <span class="ruby-identifier">source</span>[<span class="ruby-identifier">i</span>]
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Vector</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span>, <span class="ruby-string">&#39;Expected a Matrix or a value, got a Vector&#39;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">value_to_set</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">col_range</span>.<span class="ruby-identifier">size</span>, <span class="ruby-identifier">value</span>)
    <span class="ruby-identifier">row_range</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
      <span class="ruby-ivar">@rows</span>[<span class="ruby-identifier">i</span>][<span class="ruby-identifier">col_range</span>] = <span class="ruby-identifier">value_to_set</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-set_row_range" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">set_row_range</span><span
                                class="method-args">(row_range, col, value)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="set_row_range-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 411</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_row_range</span>(<span class="ruby-identifier">row_range</span>, <span class="ruby-identifier">col</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Vector</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">row_range</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">size</span>
    <span class="ruby-identifier">set_column_vector</span>(<span class="ruby-identifier">row_range</span>, <span class="ruby-identifier">col</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Matrix</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">column_count</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
    <span class="ruby-identifier">value</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">column</span>(<span class="ruby-value">0</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">row_range</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">size</span>
    <span class="ruby-identifier">set_column_vector</span>(<span class="ruby-identifier">row_range</span>, <span class="ruby-identifier">col</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@rows</span>[<span class="ruby-identifier">row_range</span>].<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>[<span class="ruby-identifier">col</span>] = <span class="ruby-identifier">value</span> }
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-set_value" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">set_value</span><span
                                class="method-args">(row, col, value)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="set_value-source">
            <pre><span class="ruby-comment"># File matrix-0.4.2/lib/matrix.rb, line 381</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_value</span>(<span class="ruby-identifier">row</span>, <span class="ruby-identifier">col</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ErrDimensionMismatch</span>, <span class="ruby-node">&quot;Expected a value, got a #{value.class}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_matrix</span>)

  <span class="ruby-ivar">@rows</span>[<span class="ruby-identifier">row</span>][<span class="ruby-identifier">col</span>] = <span class="ruby-identifier">value</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

